Skip to content

IlyaFinkelshteyn/CSharpGuidelinesAnalyzer

 
 

Repository files navigation

CSharp Guidelines Analyzer

Build status codecov csharpguidelinesanalyzer MyGet Build Status

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

Project status

This project is in its final testing phase. Expect the 1.0 stable release within a few weeks.

Get started

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>")]

Note: Due to a bug in Resharper you may not see the Suppress context menu item. To make the option accessible, temporarily suspend Resharper.

  • 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.

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.

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 MyGet. To try it out, follow the next steps:

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

About

Reports diagnostics for C# coding guidelines that are not already covered by Resharper.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.5%
  • Other 0.5%