-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some Analyzers Not Honoring All Rule Severity Using .NET 7 SDK #6545
Comments
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options#scope
Out of the 4 rules you mentioned, there are 3 that are not enabled by default: roslyn-analyzers/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif Lines 940 to 948 in b0fe62c
roslyn-analyzers/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif Lines 1357 to 1365 in b0fe62c
roslyn-analyzers/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif Lines 5738 to 5746 in b0fe62c
So this behavior is expected for them as explained in the documentation. For CA1305, it's enabled by default: roslyn-analyzers/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif Lines 1584 to 1592 in b0fe62c
So, I'd let @mavasani comment on that one. |
@Youssef1313 |
This seems to be a duplicate of #5077 (comment). It's a known limitation that we do not support both MSBuild based bulk configuration (AnalysisMode and AnalysisLevel properties) and However, note that your scenario might have a workaround due to a recent fix I made to Roslyn: If you use AnalysisMode or AnalysisLevel to bulk escalate more rules to warnings, and also set TreatWarningsAsErrors/TreatCodeAnalysisWarningsAsErrors in your MSBuild project file/targets/props, then enabled rules should get escalated to errors. You might need the latest VS/compiler for that to work though, the fix was checked in just a few months back... |
Actually, the fix was made in the analyzer package itself with #6427. So, this might work by referencing the latest 8.0 preview version of the analyzer package: https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet8/NuGet/Microsoft.CodeAnalysis.NetAnalyzers/overview/8.0.0-preview.23322.1 |
@mavasani In light of this information - I believe it would be worth while to update the documentation in the It should state that enabling analysis mode (categories or all) will invalidate any category or global severity settings specified via editorconfig, and that the first option using explicit Follow up question: |
Thanks @RyanThomas73 - filed dotnet/docs#35984 |
Yes, a list is maintained at https://github.com/dotnet/roslyn-analyzers/blob/main/src/NetAnalyzers/Core/AnalyzerReleases.Shipped.md. This is enforced to be in sync with the actual severity/enabledByDefault values with each .NET SDK release via tooling. |
Closing this issue as this is a known limitation and Manish has created the above documentation ticket to help reduce potential confusion. |
Analyzer
Multiple. Ones I've Witnessed So Far:
Diagnostic ID: CA1031
Diagnostic ID: CA1062
Diagnostic ID: CA1305
Diagnostic ID: CA5394
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 7.0.201
Describe the bug
Some rules are not honoring severity when set for all analyzers or for an entire category.
Steps To Reproduce
Enable error diagnostic severity for all rules or for a category of rules that includes one of the above analyzers.
See also https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options#scope
Test that analyzer against code which violates the analyzer rule.
For example:
Expected behavior
The analyzer flags the violation as an error.
Actual behavior
The analyzer flags the violation as a warning.
Additional context
Setting the severity by individual rule id does flag the violation at the correct severity.
Encountered while testing in a project targeting net6.0 but building using the .NET 7.0.201 SDK .
Re-tested in a project targeting net6.0 and building using the .NET 6.0.401 SDK and the severity for all analyzers works correctly.
The text was updated successfully, but these errors were encountered: