Git Product home page Git Product logo

csharpguidelinesanalyzer's Introduction

CSharp Guidelines Analyzer

Build status codecov

This Visual Studio analyzer supports you in making your code comply with the C# coding guidelines at CSharpGuidelines.

Note that many guidelines are already covered by Resharper, for which a layer file is provided. See Overview for the list of supported rules.

Analyzer in action

Get started

The latest version requires Visual Studio 2017 with Update 5 or higher. To get instant feedback on all files in your solution, activate Full Solution Analysis.

  • From the NuGet package manager console:

    Install-Package CSharpGuidelinesAnalyzer

    or, if you are using Visual Studio 2017 with Update 3:

    Install-Package CSharpGuidelinesAnalyzer -version 2.0.0

    or, if you are using Visual Studio 2015 with Update 2 or higher:

    Install-Package CSharpGuidelinesAnalyzer -version 1.0.1

  • Rebuild your solution

  • Optional: Reference CSharpGuidelines.Layer.DotSettings in your existing Resharper preferences

Rule configuration

The behavior of a few rules can optionally be customized using a configuration file. See documentation for details.

Suppressing rules

Rule warnings can be suppressed at various scopes, ranging from per line to at the project or solution level.

  • With #pragma lines, for example:
#pragma warning disable AV1532 // Loop statement contains nested loop
    foreach (string item in itemArray)
#pragma warning restore AV1532 // Loop statement contains nested loop

On the location of a warning, press Ctrl+. or Alt+Enter and select Suppress, in Source.

  • In GlobalSuppressions.cs, for example:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Maintainability", "AV1532:Loop statement contains nested loop", Justification = "<Pending>", Scope = "member", Target = "~M:CSharpGuidelinesDemo.Demo.RunDemo(System.String[][],System.Boolean,System.String)~System.Collections.Generic.List{System.String}")]

On the location of a warning, press Ctrl+. or Alt+Enter and select Suppress, in Suppression File. Note that you can broaden the suppression scope by removing the Target and/or Scope attributes:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Maintainability", "AV1532:Loop statement contains nested loop", Justification = "<Pending>")]
root = true

[*.cs]
dotnet_diagnostic.av1115.severity = error
dotnet_diagnostic.av1130.severity = suggestion
  • In a custom .ruleset file, which contains Code Analysis settings:

Right-click your project, select Properties, tab Code Analysis. Click Open, expand CSharpGuidelinesAnalyzers and uncheck the rules you want to disable. When you save changes, a .ruleset file is added to your project.

Alternatively, navigate to your project in Solution Explorer and expand References, Analyzers, CSharpGuidelinesAnalyzer. Then right-click on one of the rules and select Set Rule Set Severity. These changes are stored in a .ruleset file in your project.

To apply the custom ruleset to the entire solution, move the .ruleset file next to your .sln file and browse to it on the CodeAnalysis tab for each project.

Performance

If you run these analyzers on a large codebase and are concerned about performance, consider disabling AV1568 and AV1739. These two are by far the most resource-intensive.

Contribute!

The analyzers in this project benefit a lot from testing on various codebases. Some of the best ways to contribute are to try things out, file bugs, and join in design conversations.

Trying out the latest build

After each commit, a new prerelease NuGet package is automatically published to AppVeyor at https://ci.appveyor.com/project/bkoelman/csharpguidelinesanalyzer/branch/master/artifacts. To try it out, follow the next steps:

  • In Visual Studio: Tools, NuGet Package Manager, Package Manager Settings, Package Sources
  • Open the NuGet package manager console (Tools, NuGet Package Manager, Package Manager Console)
    • Select AppVeyor CSharpGuidelinesAnalyzer as package source
    • Run command: Install-Package CSharpGuidelinesAnalyzer -pre

csharpguidelinesanalyzer's People

Contributors

bkoelman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.