crap-score

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

Updated Aug 9, 2026
One-click install
npx skills add https://github.com/adinj00/player-performance --skill crap-score-adinj00
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: crap-score
Source: https://github.com/adinj00/player-performance/tree/main/.agents/skills/crap-score
Command: npx skills add https://github.com/adinj00/player-performance --skill crap-score-adinj00

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Identifying which .NET methods are both complex and undertested is hard when coverage percentages alone hide risk. This Skill computes CRAP (Change Risk Anti-Patterns) scores for a named method, class, or source file so you can prioritize refactoring and testing efforts objectively. ## Core Features & Use Cases - Targeted CRAP Calculation: Computes CRAP scores for a specific method, class, or single source file using the formula comp^2 x (1 - cov)^3 + comp. - 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 Risk Report: Presents a sorted risk table, top offenders, quick wins, and the exact coverage needed to bring each method below a CRAP threshold. - Use Case: Ask for the CRAP score of OrderService.ProcessOrder and receive its complexity, coverage, risk level, and a recommendation such as increasing coverage from 45% to 72% or extracting sub-methods. ## Quick Start Calculate the CRAP score for the ProcessOrder method in OrderService.cs and tell me whether to add tests or refactor it.

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 a .NET method?

Run dotnet test with Cobertura coverage collection, then compute cyclomatic complexity by counting decision points like if, for, catch, and ternary operators. Apply the formula comp squared times (1 - coverage) cubed plus comp to get the CRAP score per method.

What is a good CRAP score threshold for C# code?

A CRAP score below 5 indicates simple well-tested code, 5-15 is acceptable, 15-30 is high risk needing more tests or simplification, and above 30 is critical. Methods above 30 should be refactored and covered urgently.

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

Yes, it parses Cobertura XML produced by coverlet.collector via dotnet test --collect:"XPlat Code Coverage" or by Microsoft.Testing.Extensions.CodeCoverage on .NET 9 and later. Method coverage comes from line-rate attributes or computed line hit ratios.

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

Cobertura uses compiler-generated names for async methods, lambdas, and local functions, which differ from source names. Match methods by line ranges instead of names when the names do not align.

When should I not use CRAP score analysis?

Avoid it for project-wide coverage analysis, diagnosing coverage plateaus, or deciding where to add tests across an entire project. It is designed for targeted analysis of a named method, class, or single file, not broad coverage strategy.