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
18.78k stars 4k forks source link

IDE1006 "Naming rule violation" is not triggered in all async cases #73505

Open cremor opened 2 months ago

cremor commented 2 months ago

Version Used: VS 17.9.6

Steps to Reproduce: EditorConfig:

dotnet_naming_symbols.async_methods.applicable_kinds               = method,local_function
dotnet_naming_symbols.async_methods.required_modifiers             = async

dotnet_naming_style.pascal_case_async_suffix.capitalization        = pascal_case
dotnet_naming_style.pascal_case_async_suffix.required_suffix       = Async

dotnet_naming_rule.async_methods_pascal_case_async_suffix.symbols  = async_methods
dotnet_naming_rule.async_methods_pascal_case_async_suffix.style    = pascal_case_async_suffix
dotnet_naming_rule.async_methods_pascal_case_async_suffix.severity = warning

Sample code:

public async Task Test1()
{
    await Task.Delay(1);
}

public Task Test2()
{
    return Task.Delay(1);
}

public IAsyncEnumerable<object> Test3()
{
    return null;
}

Diagnostic Id: IDE1006 Naming rule violation: Missing suffix: 'Async'

Expected Behavior: All 3 methods show the diagnostic.

Actual Behavior: Only Test1 shows the diagnostic.

I know that you explicitly have to configure a "async modifier" in the naming rule. But there is no other way to configure a rule for methods with awaitable return types.

Note: I wasn't sure about Test3, but VSTHRD200 does show it as requiring an "Async" suffix (related issue: https://github.com/microsoft/vs-threading/issues/431). Also there is this comment from @stephentoub: https://github.com/dotnet/runtime/issues/27547#issuecomment-478384285

dibarbet commented 1 month ago

(Triage) - seems to be code style / analyzers, assigning over to Sam to check if this is by design.