Analyzers for Visual Studio
The Menees.Analyzers.dll assembly provides several new compile-time rules for Visual Studio 2015:
|MEN001||Tabs should be used for indentation||
Ensures 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".
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.
|MEN002||Line is too long||Ensures 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.|
|MEN003||Method is too long||Ensures 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.|
|MEN004||Property accessor is too long||Ensures 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.|
|MEN005||File is too long||Ensures 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 used||
#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.
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.
|MEN007||Use a single return||Recommends 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.|
|MEN008||File name should match type||Ensures 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.|
|MEN009||Use the preferred exception type||Recommends preferred exception types (e.g., NotSupportedException instead of NotImplementedException). This rule is a complement to CA2201, and it includes a code fix provider.|
|MEN010||Avoid magic numbers||Recommends 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.|
|MEN011||Align using directives||Ensures 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.|
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 source code download below.
This software is CharityWare. If you use it, I ask that you make a $5 US donation to the charity of your choice.