dotnet / roslyn-analyzers

MIT License
1.56k stars 462 forks source link

"dotnet_analyzer_diagnostic.category-Performance.severity = error" not reporting CA1849 #7277

Closed marco-carvalho closed 3 months ago

marco-carvalho commented 3 months ago

Describe the bug

When configuring the dotnet_analyzer_diagnostic.category-Performance.severity option in the .editorconfig file to error, the expected behavior is that all performance category rules, including CA1849, will be treated as errors. However, CA1849 does not get reported as an error when the code violates this rule, despite other performance category rules being correctly reported as errors. This inconsistency suggests that the CA1849 diagnostic is not respecting the configuration setting specified for the performance category.

Steps To Reproduce

  1. Create a new .NET 5 (or later) project.
  2. Add a .editorconfig file to the project with the following content:
    dotnet_analyzer_diagnostic.category-Performance.severity = error
  3. Write code that violates CA1849:
    async Task ProcessDataAsync()
    {
    string data = File.ReadAllText("data.txt");
    }
  4. Build the project.

Expected behavior

The build process should fail, and an error should be reported for CA1849 violation.

error CA1849: 'File.ReadAllText(string)' synchronously blocks. Await 'File.ReadAllTextAsync(string, CancellationToken)' instead. (https://le 
arn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Actual behavior

The build completes successfully, and no error is reported for the CA1849 violation.

mpidash commented 3 months ago

Based on the documentation, rules that are disabled by default must be explicitly enabled:

Analyzer rules that are marked as disabled by default in the analyzer package must be enabled through explicit dotnet_diagnostic..severity = entries.

As CA1849 is disabled by default, adding the following line should work:

dotnet_diagnostic.CA1849.severity = error
marco-carvalho commented 3 months ago

Thanks @mpidash