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.04k stars 4.03k forks source link

Visual Studio should not report IDE0008 for static properties when csharp_style_var_when_type_is_apparent is enabled #37267

Open steve-haar opened 5 years ago

steve-haar commented 5 years ago

Version Used: Visual Studio 2019 16.2.0 Preview 3.0 .net core 2.2

Steps to Reproduce:

See demo repo

  1. Create a new c# project and set .editorconfig to the following:

    csharp_style_var_for_built_in_types = true:error
    csharp_style_var_when_type_is_apparent = true:error
  2. Add the following code:

    var date = DateTime.UtcNow;
    var color = Color.Red;

Expected Behavior: There should be no IDE0008 errors.

Actual Behavior: There are IDE0008 errors.

sharwell commented 5 years ago

📝 Note that this feature request is directly opposed to #29657, where users request that var not be allowed under this configuration.

RussKie commented 2 months ago

I'm hitting the same issue trying to configure on of dotnet repos to match the .NET style guide point 10 - i.e., force explicit type everywhere unless the type is obvious.

To that extent I tried the following but I'm still getting warned for the obvious case (line:70):

dotnet_diagnostic.IDE0007.severity = silent

dotnet_diagnostic.IDE0008.severity = warning
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = true:none

image