Open
Description
Analyzer
Diagnostic ID: IDE0003 : this and Me preferences
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 5.0.202
AND
NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers
Version: 5.0.3 (Latest)
Describe the bug
Despite the settings in the .editorconfig file, I am unable to fail my build in both Visual Studio and on the command line due to rule IDE0003.
Steps To Reproduce
- Create a new .NET 5 console application with the following .editorconfig, project file, and source file
# editorconfig.org
# top-most EditorConfig file
root = true
# C# files
[*.cs]
# this/me
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error
dotnet_diagnostic.IDE0003.severity = error
# readonly
#dotnet_style_readonly_field = true:error
#dotnet_diagnostic.IDE0044.severity = error
# Ignore CLS Compliance attribute
dotnet_diagnostic.CA1014.severity = none
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<!--ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3" PrivateAssets="All" />
</ItemGroup-->
<PropertyGroup>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
</Project>
using System;
namespace AnalyzerExample
{
public static class Program
{
static void Main(string[] _)
{
Console.WriteLine(new Dog("Fido", 3).BarkBarkBark());
}
}
internal class Dog
{
public event Action Barking;
public string Name { get; }
private int _age;
public Dog(string name, int age)
{
// qualified property
this.Name = name;
// qualified field
this._age = age;
}
public string Bark()
{
OnBark();
return _age > 1 ? "WOOF" : "woof";
}
public string BarkBarkBark()
{
// qualified method
return string.Join(' ', this.Bark(), this.Bark(), this.Bark());
}
protected virtual void OnBark()
{
// qualified event
this.Barking?.Invoke();
}
}
}
- run
dotnet build <project file> -warnaserror
- Observe no failure
- Uncomment the "readonly" .editorconfig settings as a sanity check
- I am unsure why I need to specify
dotnet_diagnostic.IDE0044.severity = error
in addition todotnet_style_readonly_field = true:error
for this to fail. Perhaps this is another problem?
- I am unsure why I need to specify
- run
dotnet build <project file> -warnaserror
- View errors
Expected behavior
A failed build whose errors mention rule IDE0003.
Actual behavior
A successful build.
Additional context
Visual Studio seems to recognize the errors in its error list, but the build still passes: