Custom Roslyn Analyzers which NIX team uses to enforce coding standards
By default - NIX Team uses StyleCop Analyzers for code quality and code style checks. The goal is to define standard approach which all projects will use.
Decision to changes those rules is up to project Tech Lead.
Applicable for: .NET 5 and higher. Partially can work for .NET 3.1.
NIX Team StyleCops comes with NuGet Package:
The package has a dependency on StyleCop.Analyzers (1.1.118) so it will be automatically installed.
- Install NuGet Package to every project in solution
- If you don't have .editorconfig yet, the installation will automatically add the .editorconfig template file to the .sln folder. Or you can do it manually: you can find file in the repository by this path
nuget/NIX.Analyzers/assets/config/.editorconfig
Now your project is using the rules described in the file. All warnings from .Net Analyzers (CAxxxx, CSxxxx) except CA1058, CA1062 marked as Messages.
You can find more information about StyleCop (SAxxxx/SXxxxx) rules here.
NIX Team has few custom code rules to ensure better software quality and following clean code practices.
Custom rules:
- Line must not be longer than 200 characters;
- Method must not be larger than 50 lines;
- File must not be larger than 1000 lines;
- Method must not have more than 5 parameters;
- Constructor must not have more than 5 parameters;
To override these rules you must use .editorconfig and specify which rule you want to override:
dotnet_diagnostic.Nix01.max_line_length = 200
dotnet_diagnostic.Nix02.max_method_lines = 50
dotnet_diagnostic.Nix03.max_file_lines = 1000
dotnet_diagnostic.Nix04.max_params_in_method = 5
dotnet_diagnostic.Nix05.max_params_in_ctor = 5
P.S. Unfortunately, Rider doesn't support PowerShell scripts on NuGet installation, so you should add .editorconfig manually.
You can find the file in the repository by this path nuget/NIX.Analyzers/assets/config/.editorconfig