Roslyn analyzers and code fixes for consistent C# formatting and test structure. The packages run in the compiler and IDE and add no application runtime dependency. Build this repository with the .NET 11 SDK or later. The compiler and IDE must host Roslyn 5.12 or later.
Packages are available from the Cntryl GitHub Packages feed. Configure
GitHub Packages authentication
with a classic personal access token that has read:packages.
dotnet nuget add source https://nuget.pkg.github.com/cntryl/index.json --name cntrylFor general C# formatting rules:
dotnet add package Cntryl.Conventions.Analyzers
dotnet add package Cntryl.Conventions.CodeFixesFor test naming and structure, add these packages to test projects:
dotnet add package Cntryl.Conventions.Testing.Analyzers
dotnet add package Cntryl.Conventions.Testing.CodeFixesThe testing rules detect xUnit, NUnit, and MSTest.
| Rule | Enforces |
|---|---|
CNTRYL0001 |
Test names in the form Should<Outcome>Given<State>When<Action>, such as ShouldRejectOrderGivenInsufficientStock. |
CNTRYL0002 |
Ordered // Arrange, // Act, and // Assert comments. |
CNTRYL1001 |
Consistent formatting across a wrapped declaration parameter list. |
CNTRYL1002 |
Blank lines between control-flow blocks and surrounding statements. |
The general fixers support Fix All. The testing fixers update references when renaming a test and preserve indentation and line endings when inserting phase comments. They offer a fix where they can identify the change from the source.
CNTRYL0001 requires Given by default and treats When as optional. Set
naming requirements and rule severity per directory in .editorconfig.
[test/**.cs]
conventions_test_naming_require_given = true
conventions_test_naming_require_when = false
dotnet_diagnostic.CNTRYL0001.severity = warning
dotnet_diagnostic.CNTRYL0002.severity = warningUse suggestion for gradual adoption in an existing suite.
dotnet test --solution Conventions.slnx -c ReleaseSee Contributing for repository conventions and the changelog for rule changes. The benchmark project measures time and allocations on representative test methods.
Cntryl Conventions is licensed under Apache 2.0.