dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.01k stars 4.03k forks source link

`dotnet_analyzer_diagnostic.category-Naming.severity` does not apply to naming rule violations #74901

Open just-ero opened 1 month ago

just-ero commented 1 month ago

Version Used

Compiler: 4.12.0-2.24416.3 (ee863ede)
.NET: 9.0.100-preview.7.24407.12
Visual Studio Code: 1.92.2, fee1edb8d6d72a0ddff41e5f71a671c23ed924b9, x64
C# Extension: v2.44.19
C# Dev Kit Extension: v1.10.10

Steps to Reproduce

  1. Create or open a C# project in Visual Studio Code.
  2. Create or edit an .editorconfig file.
  3. Add any naming rule.
  4. Add any code violating said naming rule with a severity above silent.
  5. Add the following line to the .editorconfig file:
    dotnet_analyzer_diagnostic.category-Naming.severity = silent

Expected Behavior

The naming rule violations are no longer reported.

Actual Behavior

They are.

sharwell commented 1 month ago

Naming rules have severity silent by default. Can you check to see if a severity was specified on the individual rules, or a severity was set for IDE1006 directly?

This situation may be caused by a change we made recently to diagnostic severity precedence in .editorconfig, but even though we are working to revert that change, it is considered an authoring error to have the same rule in .editorconfig listed with different severities. If the severity is specified in more than one location, the severity in both of those locations should be the same. Otherwise, the severity not being used should be removed from the file altogether.

just-ero commented 1 month ago

Yes, the rules themselves have the warning severity.

I have noticed that dotnet_analyzer_diagnostic.category-Style.severity = none is able to suppress all property rules (like dotnet_style_require_accessibility_modifiers = warning). However, rules specified explicitly (like dotnet_diagnostic.IDE0040.severity = warning) override that suppression.

sharwell commented 1 month ago

dotnet_analyzer_diagnostic.category-*.severity and dotnet_diagnostic.*.severity are in the same "category" of configuration, and thus have a well-defined precedence order. The rules like dotnet_style_require_accessibility_modifiers are separate, and their priority depends on the specific SDK version in use along with some project properties. Once .NET 9 SDK (non-preview) is released, this form will have lower priority unless EnableCodeStyleSeverity is set to true in the project file. Some preview builds of the .NET 9 SDK, as well as some build at the end of .NET 8 SDK, will place this form at higher priority as long as AnalysisLevel is set to 9 or higher in the project file.

just-ero commented 1 month ago

This is expected behavior then? If so, feel free to close.