Supressing Rules Using .editorconfig Files
See original GitHub issueI’ve been trying to use an .editorconfig file to supress rules like so:
# XML comment analysis is disabled due to project configuration
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA0001.md
dotnet_diagnostic.SA0001.severity = silent
# Single-line comment should be preceded by blank line
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1515.md
dotnet_diagnostic.SA1515.severity = silent
# A C# code element is missing a documentation header.
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1600.md
dotnet_diagnostic.SA1600.severity = silent
# A C# partial element is missing a documentation header.
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1601.md
dotnet_diagnostic.SA1601.severity = silent
# An item within a C# enumeration is missing an Xml documentation header.
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1602.md
dotnet_diagnostic.SA1602.severity = silent
# Documentation text should not be empty
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1627.md
dotnet_diagnostic.SA1627.severity = silent
# Documentation text should end with a period
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1629.md
dotnet_diagnostic.SA1629.severity = silent
# A C# code file is missing a standard file header.
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md
dotnet_diagnostic.SA1633.severity = silent
# XML comment analysis is disabled due to project configuration
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA0001.md
dotnet_diagnostic.SA0001.severity = silent
This actually works very well for the most part. However, this does not work when you want to supress SA0001. Are there any downsides or limitations to using .editorconfig to supress rules?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How do we suppress a diagnostic rule for a specific file in ...
I am trying to suppress a file in editor config on diagnostic scan. Below is my code, Can anyone help . [*.File.cs] generated_code...
Read more >Suppress code analysis warnings - .NET
You can disable a rule that's causing a warning by setting its severity to none in an EditorConfig or AnalyzerConfig configuration file.
Read more >Use EditorConfig | ReSharper Documentation
EditorConfig is a configuration file convention that is used to define and maintain consistent code styles between team members working on the ...
Read more >Use EditorConfig | JetBrains Rider Documentation
EditorConfig is a configuration file convention that is used to define and maintain consistent code styles between team members working on the ...
Read more >EditorConfig Language Service
Another way to suppress the error is by right-clicking the error in the Error List.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is not true @sharwell ; This works 100% for me:
Also:
I have zero intention of exposing XML documentation for a UnitTest project, so I don’t see how I should be forced to add it. That’s not a “problem with the project configuration” at all.
I still want to have StyleCop enforcing all non-XML-doc rules though on those unit test projects.
You said it yourself StyleCop would potentially not work correctly with the XML generation disabled, not me. That sounded like a bug description if I’ve ever seen one.
That behavior from the compiler sounds like intended behavior to me. Is it not? In any case, if summaries are reported as normal comments in that situation to the analyzer, I don’t see why there would be any problems? Can’t you then just handle them as normal comments on StyleCop too?
Again, StyleCop has many more features besides comment analysis, so I see zero reason to create this hard coupling with XML generation. I want to have all other bonuses of StyleCop in my test projects for consistency, but class documentation makes zero sense in unit test projects for us (they do on test helper projects though, as those are reusable libraries), so I don’t want those being generated.
Adding forced XML generation in these projects is a clear violation of the principle of least astonishment: it will create confusion among our teams, or require “hack”-style comments to be added justifying the flag’s presence due to weird behavior from StyleCop.