dotnet / roslyn-analyzers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

marco-carvalho opened this issue · comments

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
  1. Write code that violates CA1849:
async Task ProcessDataAsync()
{
    string data = File.ReadAllText("data.txt");
}
  1. 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.

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