crap-score

Calculates CRAP scores for .NET methods by combining cyclomatic complexity with Cobertura coverage data.

Updated May 2, 2026
One-click install
npx skills add https://github.com/hdeshev/pi-config --skill crap-score-hdeshev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: crap-score
Source: https://github.com/hdeshev/pi-config/tree/main/agent/skills/crap-score
Command: npx skills add https://github.com/hdeshev/pi-config --skill crap-score-hdeshev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Simple code coverage percentages hide risk: a method can be 80% covered yet still be dangerously complex and undertested. This Skill computes CRAP (Change Risk Anti-Patterns) scores for .NET code, combining cyclomatic complexity with line coverage to pinpoint which methods are genuinely risky and need tests or refactoring first. ## Core Features & Use Cases - CRAP Score Calculation: Applies the formula comp^2 x (1 - cov)^3 + comp per method, class, or file, and classifies results into Low, Moderate, High, and Critical risk bands. - Coverage Collection Guidance: Detects the coverage package in the test project (coverlet.collector or Microsoft.Testing.Extensions.CodeCoverage) and runs the correct dotnet test command to produce Cobertura XML. - Actionable Recommendations: Computes the exact coverage needed to bring a method below a CRAP threshold, or flags methods whose complexity alone exceeds the threshold and must be refactored. - Use Case: After a sprint, ask which methods in OrderService are riskiest. The Skill runs coverage, counts decision points per method, and returns a sorted table showing ProcessOrder at CRAP 28.4 (High) with a recommendation to raise coverage from 45% to 72%. ## Quick Start Calculate the CRAP scores for all methods in OrderService.cs using my test project's coverage data and tell me which methods need tests first.

Frequently Asked Questions about crap-score

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I calculate CRAP score for C# methods?▼

Run dotnet test with coverage collection to produce a Cobertura XML report, then compute cyclomatic complexity per method by counting decision points like if, case, and loops. Apply the formula comp^2 x (1 - cov)^3 + comp using each method's line-rate from the coverage data.

What is a good CRAP score threshold for .NET code?▼

A CRAP score below 5 indicates simple, well-tested code, while 5-15 is acceptable for most methods. Scores of 15-30 are high risk needing more tests or simplification, and anything above 30 is critical and should be refactored and covered urgently.

Does CRAP score analysis work with coverlet and Cobertura coverage files?▼

Yes, it works with Cobertura XML produced by coverlet.collector via dotnet test --collect:"XPlat Code Coverage", and with Microsoft.Testing.Extensions.CodeCoverage on .NET 9 and later using the --coverage-output-format cobertura option.

Why do method names in Cobertura XML not match my source code?▼

The compiler generates mangled names for async methods, lambdas, and local functions, so Cobertura entries may not align with source names. Match methods by line ranges instead of names when this happens.

When should I not use CRAP score analysis?▼

Do not use it when you only want to run tests, write new tests, or get a plain coverage percentage without complexity context. CRAP analysis is specifically for prioritizing risky code that is both complex and undertested.

Can increasing test coverage always lower a high CRAP score?▼

No. When cyclomatic complexity is 15 or higher, the minimum possible CRAP score equals the complexity itself, so coverage alone cannot bring it below the threshold. The method must first be refactored, for example by extracting sub-methods.