As I understand it, the general recommendation when starting with ATC rules on an existing project, is to initially suppress all failing rules in your Custom
section in order to get back to โ
state for the project, and then later clean up the code and remove the suppressions one by one in nice clean commits.
The challenge is that this initial suppression list takes a long time to hand-write. There is no easily translatable output from dotnet build
that you can use unless you do serious amounts of manipulation (sorting, cleaning format etc.) in an editor or spread sheet to get the right format.
It would be really nice if we could somehow generate this list for the user. I am not really a .Net guy, so I don't know how this could be plugged into the ecosystem (as it is only dotnet build that knows which rules are violating it is probably not a good job for the atc updater to do this).
I envision the tool generating the actual syntax needed for insertion in the .editorconfig files, or even auto-adding to the custom sections. It would be a bonus if rues that only fail in test/
are only excluded in that folder, so as not to "cloak" future errors in production code.
Ideally, I would wish for a format where each line also contains information about the rule, e.g. the description and maybe link:
# StyleCop
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers
dotnet_diagnostic.SA1309.severity = none # https://documentation.help/StyleCop/SA1309.html FieldNamesMustNotBeginWithUnderscore
dotnet_diagnostic.SA1402.severity = none # https://documentation.help/StyleCop/SA1402.html FileMayOnlyContainASingleClass
# SonarSource
dotnet_diagnostic.S101.severity = none # https://rules.sonarsource.com/csharp/RSPEC-101 Types should be named in PascalCase
dotnet_diagnostic.S108.severity = none # https://rules.sonarsource.com/csharp/RSPEC-108 Nested blocks of code should not be left empty
# https://cezarypiatek.github.io/post/non-nullable-references-in-dotnet-core/
dotnet_diagnostic.CS8600.severity = none # Converting null literal or possible null value to non-nullable type.
dotnet_diagnostic.CS8601.severity = none # Possible null reference assignment.
# Meziantou
# https://www.meziantou.net/enforcing-asynchronous-code-good-practices-using-a-roslyn-analyzer.htm
dotnet_diagnostic.MA0002.severity = none # https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0002.md IEqualityComparer<string> or IComparer<string> is missing
dotnet_diagnostic.MA0004.severity = none # https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0004.md Use Task.ConfigureAwait(false)
The example above is a very shortened snippet from the hand-crafted exclusion list I made when adding ATC rules to a small Swagger API project. The full list originally contained > 100 rule suppressions, and adding the links and comments took quite a few hours, but I judged that it would be so much easier to motivate the developers to clean up the rules if they could actually read which one they were commenting out instead of just going by trial and error and having VS do useless Bing searches for help.
To me this sounds like a perfect use-case for automation.