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.57k stars 3.95k forks source link

The editor config should allow specifying whether a warning is included in code cleanup #73321

Open SoggyBottomBoy opened 2 weeks ago

SoggyBottomBoy commented 2 weeks ago

Summary

The editor config should allow for some configuration options per rule that state whether the rule is included as part of code cleanup.

Background and Motivation

The VS option to Fix analyzer warnings and errors set in EditorConfig can be very aggressive and unhelpful for some warnings that are commonly generated when writing code. Namely CS0219 - The variable 'variable' is assigned but its value is never used is commonly created when writing code, and saving the file will automatically remove these. Changing the rule to suggestion will mean that it is not cleaned up on save, however, the suggestion is much harder to spot than errors/warnings.

We currently have this rule as warning in CI but suggestion for developers. It is frustrating when this suggestion is not immediately obvious in VS and only caught in CI which can take up to 10min and relies on the developer checking their CI workflow.

Proposed Feature

I'm suggesting that a cleanup option is added to the editor config so that a analyzer can both be a error/warning and not be cleaned up on save.

dotnet_diagnostic.CS0219.severity = warning
dotnet_diagnostic.CS0219.cleanup = false

Alternative Designs

I guess one alternative is make this suggestion more obvious in visual studio. I'm not sure if there is an option to do this, but the red and green squiggles for errors/warnings are very obvious. The suggestion is three dots that are hard to spot. I believe this is a blue squiggle in VSCode, and VS could allow for the same?