RepoMicrosoftMicrosoftpublished Jul 26, 2026seen 10h

microsoft/crap4csharp

Open original ↗

Captured source

source ↗
published Jul 26, 2026seen 10hcaptured 10hhttp 200method plain

microsoft/crap4csharp

Description: Agentic port of https://github.com/unclebob/crap4java

License: CC0-1.0

Stars: 0

Forks: 0

Open issues: 2

Created: 2026-07-26T18:36:50Z

Pushed: 2026-07-27T06:49:44Z

Default branch: master

Fork: no

Archived: no

README:

crap4csharp

Attribution

crap4csharp continues the lineage of Robert C. ("Uncle Bob") Martin's original crap4clj, and is a C# port of its Java sibling crap4java.

---

crap4csharp is a standalone CRAP metric tool for C# projects, modeled after crap4java.

It combines method cyclomatic complexity with Coverlet (Cobertura) method coverage and reports CRAP scores. On each run it deletes stale coverage artifacts, runs coverage, then analyzes the selected files.

Formula

CRAP = CC^2 * (1 - coverage)^3 + CC

  • CC is cyclomatic complexity.
  • coverage is method coverage fraction from Cobertura line counters (the .NET analog of JaCoCo

INSTRUCTION counters).

Coverage Pipeline

For each invocation, per module (nearest .sln, else .csproj, else the project root):

1. Delete stale coverage artifacts:

  • coverage/

2. Run dotnet test --collect:"XPlat Code Coverage" --results-directory coverage 3. Read the produced coverage.cobertura.xml 4. Analyze the selected C# files

Build and Test

dotnet test

Run

Build:

dotnet build -c Release

From the project root you want to analyze:

dotnet run --project src/Crap4CSharp -c Release

CLI

--help Print usage to stdout
(no args) Analyze all C# files under src/
--changed Analyze changed C# files under src/
Analyze only these files
Analyze all C# files under each directory's src/ subtree

Examples:

dotnet run --project src/Crap4CSharp -c Release -- --help
dotnet run --project src/Crap4CSharp -c Release
dotnet run --project src/Crap4CSharp -c Release -- --changed
dotnet run --project src/Crap4CSharp -c Release -- src/Sample.cs
dotnet run --project src/Crap4CSharp -c Release -- project-a project-b

Exit codes

  • 0 success, threshold respected
  • 1 invalid CLI usage, or a fatal error (e.g. no tests ran / no coverage produced — see Notes)
  • 2 CRAP threshold exceeded (> 8.0)

Notes

  • Fail fast: if a module runs no tests or produces no coverage, crap4csharp exits non-zero

rather than continuing — a deliberate, stricter departure from crap4java. A method simply absent from an otherwise-populated report is still reported as N/A.

  • Report output is sorted by CRAP descending, with N/A at the bottom.