CodeEnforcer.Analyzers
0.1.0-ci.10
dotnet add package CodeEnforcer.Analyzers --version 0.1.0-ci.10
NuGet\Install-Package CodeEnforcer.Analyzers -Version 0.1.0-ci.10
<PackageReference Include="CodeEnforcer.Analyzers" Version="0.1.0-ci.10" />
<PackageVersion Include="CodeEnforcer.Analyzers" Version="0.1.0-ci.10" />
<PackageReference Include="CodeEnforcer.Analyzers" />
paket add CodeEnforcer.Analyzers --version 0.1.0-ci.10
#r "nuget: CodeEnforcer.Analyzers, 0.1.0-ci.10"
#:package CodeEnforcer.Analyzers@0.1.0-ci.10
#addin nuget:?package=CodeEnforcer.Analyzers&version=0.1.0-ci.10&prerelease
#tool nuget:?package=CodeEnforcer.Analyzers&version=0.1.0-ci.10&prerelease
CodeEnforcer
CodeEnforcer is a repository-local C# structure gate. It scans tracked files and fails when file length, folder size, project-root folder size, or one-file-folder patterns cross enforced limits.
The CLI is designed for CI and pre-commit usage: exclusions are centralized in .config/code-enforcer/justifications.json so structural debt is visible in review. The repository also ships CodeEnforcer.Analyzers, a Roslyn analyzer package for compiler and IDE feedback.
What You Get
- A
code-enforcer.NET tool for repository-wide checks. - A
CodeEnforcer.Analyzerspackage for compile-time and IDE feedback. - A one-command
initflow that writes config files and installs the pre-commit hook. - CLI CRUD for exceptions and justifications, so teams do not need to hand-edit JSON.
- Shared CLI/analyzer rule IDs:
CE0001throughCE0004. - A commit-time CLI-only anti-gaming rule:
CE0005.
Install
Install the CLI tool:
dotnet tool install --global CodeEnforcer --prerelease
Add the analyzer to a project:
dotnet add package CodeEnforcer.Analyzers --prerelease
Rules
CE0001: A tracked C# file exceedsmaxLinesSoftand is not listed injustifications.json.CE0002: A tracked C# file exceedsmaxLinesHardand its exclusion has no non-empty justification.CE0003: A folder contains more tracked C# files thanmaxFilesPerDir.CE0004: A folder containing a.csprojcontains more tracked C# files thanmaxFilesPerRootDir.CE0005: The repository contains more than two folders that have exactly one tracked C# file and no other tracked files. This is CLI-only because it needsgit ls-files.
Generated and build-output files are skipped:
bin/**obj/***.g.cs*.Designer.cs
Run
From a repository that contains .config/code-enforcer/code-enforcer.json:
code-enforcer
Or explicitly:
code-enforcer check
Run from this source checkout:
dotnet run --project src/CodeEnforcer -- check --root . --config .config/code-enforcer/code-enforcer.json
Run the complete verification gate:
./scripts/verify.ps1
Build the .NET tool
./scripts/build-tool.ps1
dotnet tool install --global --add-source ./artifacts/packages CodeEnforcer
The installed command is:
code-enforcer
Initialize A Repository
Create the default config files and install the git pre-commit hook:
code-enforcer init
This creates:
.config/code-enforcer/code-enforcer.json.config/code-enforcer/justifications.json.githooks/pre-commit
It also runs git config core.hooksPath .githooks. Existing files are kept unless --force is supplied.
The same build script also creates CodeEnforcer.Analyzers.0.1.0.nupkg.
Roslyn Analyzer
Install the analyzer package into a consuming project:
dotnet add package CodeEnforcer.Analyzers --source ./artifacts/packages
Configure analyzer limits and exclusions in .editorconfig. See analyzer for install, configuration, and CLI differences.
Configuration
CodeEnforcer walks from the current directory to parent directories until it finds:
.config/code-enforcer/code-enforcer.json
The same folder must also contain:
.config/code-enforcer/justifications.json
See configuration for CLI schema details and examples.
Manage Justifications
Use the CLI to create, read, update, and delete entries in .config/code-enforcer/justifications.json:
code-enforcer justifications add --type file --path src/App/Large.cs --justification "Scheduled for split"
code-enforcer justifications list
code-enforcer justifications show --type file --path src/App/Large.cs
code-enforcer justifications update --type file --path src/App/Large.cs --justification "Split after adapter cleanup"
code-enforcer justifications remove --type file --path src/App/Large.cs
exceptions is an alias for justifications, so code-enforcer exceptions add ... works the same way.
Development
See development for local verification, git hook setup, and package build instructions.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
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 |
|---|---|---|
| 0.1.0-ci.10 | 80 | 6/12/2026 |
| 0.1.0-ci.9 | 74 | 6/12/2026 |
| 0.1.0-ci.8 | 70 | 6/12/2026 |
| 0.1.0-ci.7 | 66 | 6/12/2026 |
| 0.1.0-ci.6 | 70 | 6/12/2026 |
| 0.1.0-ci.5 | 70 | 6/12/2026 |