question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supressing Rules Using .editorconfig Files

See original GitHub issue

I’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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
julealgoncommented, Dec 17, 2019

The .editorconfig file can only be used to disable diagnostics that are reported at a location within a file.

This is not true @sharwell ; This works 100% for me:

[/*Tests/**]
# SA0001: XML comment analysis is disabled due to project configuration
dotnet_diagnostic.SA0001.severity = none

Also:

SA0001 should not be disabled. This diagnostic means there is a problem with the project configuration that needs to be corrected.

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.

5reactions
julealgoncommented, Dec 21, 2019

This is not correct.

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.

When the XML output is disabled, the compiler (sometimes) interprets /// as a normal line comment and explicitly tells the analyzers that there are no documentation comments in the source files.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found