Home

Awesome

windows build & test Nuget

Analyzers

This project provides several new C# code analysis rules for Visual Studio 2015 and later. These rules can be used standalone, or they can be used with other analyzers like StyleCopAnalyzers and Code-Cracker.

Many of the rule limits can be configured using a Menees.Analyzers.Settings.xml file, which must comply with the Menees.Analyzers.Settings.xsd schema. The schema and Settings.cs file (for "documentation") are available in the Menees.Analyzers source code. A project using Menees.Analyzers with a custom settings file should set the Build Action for its Menees.Analyzers.Settings.xml file to "C# analyzer additional file".

This software is CharityWare. If you use it, I ask that you donate something to the charity of your choice.

IDTitleComment
MEN001Tabs should be used for indentationEnsures tabs are used for indentation instead of spaces. This is the opposite of StyleCop's SA1027: TabsMustNotBeUsed rule. This is similar to the StyleCop+ rule SP2001: CheckAllowedIndentationCharacters when set to "Tabs only".<br><br>This rule is off by default because it conflicts with Visual Studio's default settings, which use spaces instead of tabs for indentation. This rule can be enabled using a custom ruleset file, and it includes a code fix provider.
MEN002Line is too longEnsures that lines are not longer than 160 characters. This is similar to the StyleCop+ rule SP2100: CodeLineMustNotBeLongerThan. The MaxLineColumns and TabSize values for this rule can be configured in Menees.Analyzers.Settings.xml.
MEN002ALine is longNotifies when lines are longer than 160 characters. This rule is off by default because MEN002 takes precedence and is sufficient for most cases. If you enable this rule, then you should also configure NotifyLineColumns to be less than MaxLineColumns in Menees.Analyzers.Settings.xml.
MEN003Method is too longEnsures that methods are not longer than 120 lines. This is similar to the StyleCop+ rule SP2101: MethodMustNotContainMoreLinesThan. The MaxMethodLines limit for this rule can be configured in Menees.Analyzers.Settings.xml.
MEN004Property accessor is too longEnsures that property accessors are not longer than 80 lines. This is similar to the StyleCop+ rule SP2102: PropertyMustNotContainMoreLinesThan. The MaxPropertyAccessorLines limit for this rule can be configured in Menees.Analyzers.Settings.xml.
MEN005File is too longEnsures that files are not longer than 2000 lines. This is similar to the StyleCop+ rule SP2103: FileMustNotContainMoreLinesThan. The MaxFileLines limit for this rule can be configured in Menees.Analyzers.Settings.xml.
MEN006#regions should be usedRecommends that #regions be used when there are over 100 lines in a file or if there is more than one class, struct, enum, or interface defined in a file.<br><br>This rule is off by default because it conflicts with StyleCop's SA1124: DoNotUseRegions rule. This rule can be enabled using a custom ruleset file. The MaxUnregionedLines limit for this rule can be configured in Menees.Analyzers.Settings.xml.<br><br>Note: Menees VS Tools can be used to easily add, collapse, and expand #regions in C# code (as well as in VB, XML, XAML, HTML, SQL, JavaScript, and TypeScript code).
MEN007Use a single returnRecommends that only a single return statement should be used in a code block. "One entry, one exit" keeps control flow simple and makes refactoring easier.
MEN008File name should match typeEnsures that a file name matches or includes the name of the main type it contains. The TypeFileNameExclusions for this rule can be configured in Menees.Analyzers.Settings.xml.
MEN009Use the preferred exception typeRecommends preferred exception types (e.g., NotSupportedException instead of NotImplementedException). This rule is a complement to CA2201, and it includes a code fix provider.
MEN010Avoid magic numbersRecommends that named constants be used instead of numeric literals (i.e., magic numbers). The AllowedNumericLiterals for this rule can be configured in Menees.Analyzers.Settings.xml.
MEN011Align using directivesEnsures that using directives are aligned. This is important when using directives are nested inside a namespace (per SA1200: UsingDirectivesMustBePlacedWithinNamespace) because Visual Studio will often fail to indent them correctly if they're added while code contains syntax errors. This rule includes a code fix provider.
MEN012Flags should be powers of twoFlags enum members should be powers of two or bitwise-or combinations of named members. This rule is a complement to CA2217.
MEN013Use UTC timeRecommends UTC times because they're unambiguous and always increasing. This rule includes a code fix provider.
MEN014Prefer TryGetValueRecommends calling TryGetValue (for a single lookup and retrieval) instead of ContainsKey and this[key] with duplicate lookups.
MEN015Use Preferred TermsSimilar to the old FxCop CA1726 rule except this rule only checks single terms (not double terms). So it uses a slightly different set of default preferred terms (omitting double terms like LogOn), and it includes Id as a preferred term over ID (per FxCop's CA1709 rule).
MEN016Avoid Top-Level StatementsC# top-level statements are only for toy/example programs and should be avoided in long-term code for consistency and maintainability.
MEN017Remove Unused Private SetterA private set accessor is not needed when an auto property is only assigned in the constructor. Inspired by C# Essentials' Use Getter-Only Auto-Property.
MEN018Use Digit SeparatorsNumeric literals should use digit separators ('_' from C# 7) to improve readability. This applies to hexadecimal, binary, and integer or real literals.