/roslyn-analyzers

Roslyn Diagnostic Analyzers are customized compiler errors providing real-time feedback to C# developers. Each Analyzer optionally includes an automatic Code Fixer.

Primary LanguageC#MIT LicenseMIT

Introduction

Roslyn Diagnostic Analyzers are customized compiler errors providing real-time feedback to C# developers. Each Analyzer optionally includes an automatic Code Fixer. Microsoft (and other organizations) offer many analyzers, but the market is nascent.

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:

Getting Started

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.

Visual Studio 2019 Support

These packages reference Microsoft.CodeAnalysis version 3.6, which shipped with Visual Studio 2019 16.6.

Still on Visual Studio 2017?

If you are still working with Visual Studio 2017, use the 1.0.x versions of the analyzers.