StyleCopPlus 3.3.0

dotnet add package StyleCopPlus --version 3.3.0                
NuGet\Install-Package StyleCopPlus -Version 3.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StyleCopPlus" Version="3.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StyleCopPlus --version 3.3.0                
#r "nuget: StyleCopPlus, 3.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StyleCopPlus as a Cake Addin
#addin nuget:?package=StyleCopPlus&version=3.3.0

// Install StyleCopPlus as a Cake Tool
#tool nuget:?package=StyleCopPlus&version=3.3.0                

StyleCopPlus Analyzers and Refactorings

CI Build NuGet Version

This project is an implementation of StyleCop+ rules using the .NET Compiler Platform (Roslyn) as well as some additional opinionated refactorings and analyzers. Original project is available on CodePlex.

Installation

This project is available as a NuGet package and VSIX extension. Currently Roslyn does not support loading refactorings from NuGet packages so you need to install VSIX extension in order to get full functionality.

Latest VSIX and NuGet Packages

Analyzers

  • SP1001 (Invalid Exception Message) - validates exception message to match best practices. Inspired by Microsoft guidelines and StackOverflow discussion.
  • SP1002 (Cancellation token name) - validates that parameters of type CancellationToken are named ct.
  • SP1003 (Separate return with empty line) - validates that return statement in block is separated with empty line.
  • SP1131 (Unsafe Condition Analyzer) - validates that constant pattern matching is used instead of == operator to avoid typos like if (flag = true), also suggests using negated not pattern instead of != operator.
  • SP2100 (Line Too Long Analyzer) - validates that code lines do not exceed 110 symbols.
  • SP2101 (Method Too Long Analyzer) - validates that methods length do not exceed 50 lines.
  • SP2102 (Property Too Long Analyzer) - validates that property accessors do not exceed 40 lines.
  • SP2103 (File Too Long Analyzer) - validates that files length do not exceed 400 lines.

Configuration

Analyzer line limits can be configured through StyleCop configuration file. Add the following snippet with configured values to the end of the file:

"styleCopPlusRules": {
    "maxLineLength": 110,
    "maxFileLength": 400,
    "maxPropertyAccessorLength": 40,
    "maxMethodLength": 50
}

Refactorings

  • Check Parameters - adds custom null check code for method or constructor parameters.
  • Create Variable From Invocation - saves result of method or property to local variable.
  • Duplicate Method - creates an exact copy of the method under cursor.
  • Introduce Field - creates and initializes class field from constructor parameter.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.3.0 2,214 6/12/2024
3.2.0 2,726 6/3/2024
3.1.1 119 5/20/2024
3.0.0 66,852 12/27/2021

Migration to GitHub actions, other minor enhancements.