Roslyn Diagnostic Analyzers are customized compiler errors providing real-time feedback to C# developers. Many Analyzers include an automatic Code Fixer. While Microsoft (and other organizations) offer many analyzers, the market is nascent. Moreover, many tools offer a rich set of rules, but lack the shift-left integration that Roslyn achieves.
We have a policy whereby Code Reviewers ask themselves if a review comment can be automated. If so, and if a Diagnostic Analyzer is the right tool for the scenario in question, and if an Analyzer does not readily exist in the market already, an issue is created to track the need. That is, all analyzers herein are based on real-world code review feedback. This project is the result. It was open-sourced in 2020.
Consult the following for details on the available rules:
Add the rules using Visual Studio's Package Manager, locating these packages on nuget.org. Rules are generally enabled by default. Use the .editorconfig file to enable or disable each of them and set their severity level as desired.
Enabling a new rule on a legacy codebase can be daunting. Some rules (e.g., Avoid Duplicate Code, Avoid Static Classes) support configuration and whitelisting - again via the .editorconfig.
These packages reference Microsoft.CodeAnalysis version 3.6, which shipped with Visual Studio 2019 16.6.
If you are still working with Visual Studio 2017, use the 1.0.x versions of the analyzers.
Learn more about the CI/CD pipeline.