Search code examples
c#visual-studio-codestylecopeditorconfig

Ignore StyleCop rule in Visual Studio Code


I do my development in Visual Studio Code and have recently started using StyleCop to improve my coding style in C#.

In my .csproj file, I added a PackageReference to StyleCop.Analyzers and can now see several warnings in the Problems window. However, I do not want to follow one of the suggestions, SA1633, "The file header is missing or not located at the top of the file". Following suggestions, I created a .editorconfig file at the root of my solution (one directory above my project) and added the lines

# Don't want to require file header
dotnet_diagnostic.SA1633.severity = none

However the warning still shows up both in the Problems window and when I build the solution with dotnet build. All the discussion I have found that talks about this is for Visual Studio, not Visual Studio Code.

What is the proper way, in Visual Studio Code, to change the severity of a StyleCop rule?


Solution

  • @NPras got me pointed in the right direction. There were two different issues.

    1. I had let an extension create a default .editorconfig file for me. When I added my rules to the end, I did not take into account the qualifiers and so they inherited the qualifiers of the last entry which was not what I needed. I added the qualifier of [*.cs] before my rules and dotnet build began respecting the rules.

    2. The Problems window in Visual Studio does not pick up on a reduction of severity upon saving an .editorconfig file (though it apparently does pick up changing the severity from none to warn). The warnings were still being shown in the window. Restarting Visual Studio Code or even just reloading the window (command Developer: Reload Window) fixed this synchronization/caching (?) issue. It is not a quick process, but altering the severity of these checks should not be a frequent occurrence and so that workaround is acceptable to me.