-
-
Save MelbourneDeveloper/dfb17737c1a74641c86641531b51e5eb to your computer and use it in GitHub Desktop.
[*.{cs,vb}] | |
dotnet_diagnostic.CA1062.severity = none | |
# IDE0022: Use block body for method | |
csharp_style_expression_bodied_methods = true | |
# IDE0032: Use auto property | |
dotnet_style_prefer_auto_properties = true | |
#CSharpier Incompatible Rules | |
dotnet_diagnostic.SA1009.severity = none | |
dotnet_diagnostic.SA1111.severity = none | |
dotnet_diagnostic.SA1633.severity = none | |
dotnet_diagnostic.SA1502.severity = none | |
#Don't like these | |
dotnet_diagnostic.SA1512.severity = none | |
dotnet_diagnostic.SA1623.severity = none | |
dotnet_diagnostic.SA1515.severity = none | |
dotnet_diagnostic.SA1516.severity = none | |
#Not sure why this is necessary | |
dotnet_diagnostic.CA1016.severity = none | |
#What's the recommendation these days? | |
dotnet_diagnostic.SA1309.severity = none | |
dotnet_diagnostic.SA1101.severity = none | |
#Too onerous | |
dotnet_diagnostic.SA1615.severity = none | |
dotnet_diagnostic.SA1600.severity = none | |
dotnet_diagnostic.SA1611.severity = none | |
#This is an analyzer bug when using records | |
dotnet_diagnostic.SA1313.severity = none | |
#This also seems to be a bug when using array initializers | |
dotnet_diagnostic.SA1010.severity = none | |
dotnet_diagnostic.SA1011.severity = none | |
# IDE0040: Add accessibility modifiers | |
dotnet_style_require_accessibility_modifiers = never |
<Project> | |
<PropertyGroup> | |
<TargetFramework>net8.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<WarningsNotAsErrors></WarningsNotAsErrors> | |
<Deterministic>true</Deterministic> | |
<LangVersion>Latest</LangVersion> | |
<DebugSymbols>true</DebugSymbols> | |
<EnableNETAnalyzers>true</EnableNETAnalyzers> | |
<AnalysisLevel>latest</AnalysisLevel> | |
<AnalysisMode>AllEnabledByDefault</AnalysisMode> | |
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | |
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild> | |
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis> | |
<RunAnalyzers>true</RunAnalyzers> | |
<Nullable>enable</Nullable> | |
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> | |
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0"/> | |
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"/> | |
</ItemGroup> | |
</Project> |
Hi @sharwell . Thanks for all the comments. Let's unpack these one by one.
StyleCop.Analyzers version 1.1.118 only supports C# 7 and earlier. If you want to use newer versions of C#, you need to use a newer preview release (ideally the latest beta version).
I had not used StyleCop much, and only discovered this yesterday. It's a good package because it seems to add a lot of formatting rules that have been sorely missing in the C# experience. I mostly work in Dart these days, and the formatter is complete and integrated into the IDE. Currently, I use CSharpier and I have to manually format the code before I push it.
I noticed that some of the rules are buggy, and this is probably because it doesn't support the latest version. Still, I'm not keen to install a beta version of the package. If the analyzers become too problematic with the latest version of C#, I will have to fall back on CSharpier only.
In general, lines with the syntax dotnet_diagnostic.{id}.severity should go in .globalconfig instead of .editorconfig.
Oh man. There's a new file format now? I didn't see this one creep in. There have been so many different formats, it's hard to keep up. I can migrate over to this new format. Can you tell me why this new format exists, and why it's better than editor config? There is documentation here, but it's not clear what the advice is.
Can you tell me why this new format exists, and why it's better than editor config
It applies to all files in a build and not just the ones matching the filter (i.e. it works like a proper replacement for .ruleset files). The format is equivalent to .editorconfig aside from section headers.
Initial notes (commenting on Revision 2):
Several items in Directory.Build.props here are unnecessary
RunAnalyzersDuringBuild
defaults to the value ofRunAnalyzers
, so if both are the same only the latter needs to be included. Also, the default value here istrue
, so both of these could be removed.RunAnalyzersDuringLiveAnalysis
defaults to the value ofRunAnalyzers
, so if both are the same only the latter needs to be included. Also, the default value here istrue
, so both of these could be removed.CodeAnalysisTreatWarningsAsErrors
defaults to the value ofTreatWarningsAsErrors
, so if the values are the same only the latter needs to be included.StyleCop.Analyzers version 1.1.118 only supports C# 7 and earlier. If you want to use newer versions of C#, you need to use a newer preview release (ideally the latest beta version).
In general, lines with the syntax
dotnet_diagnostic.{id}.severity
should go in .globalconfig instead of .editorconfig.Setting the value
dotnet_style_prefer_auto_properties = true
will not enable IDE0032 for command line builds. Starting with Visual Studio 17.9 Preview 2 (dotnet/roslyn#69843), the recommended way to enable this would be to setdotnet_style_prefer_auto_properties = true:warning
. For earlier versions, you'll need to have a separate line:I don't believe there is a way to "enable all rules" for several reasons: