crap-score

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

Updated Jul 12, 2026
One-click install
npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill crap-score-patrick-rex
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: crap-score
Source: https://github.com/Patrick-Rex/DotNetTechSamples/tree/main/.agents/plugins/dotnet-test/skills/crap-score
Command: npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill crap-score-patrick-rex

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Identifying which .NET methods are risky because they are both complex and undertested is hard when looking at coverage percentages alone. 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 - Coverage Collection: Runs dotnet test with the correct coverage command for coverlet.collector or Microsoft.Testing.Extensions.CodeCoverage on .NET 9 and .NET 10+. - Complexity Analysis: Counts cyclomatic complexity per method from decision points such as if, case, loops, catch, &&, ||, ??, and pattern matching arms. - Risk Reporting: Produces a sorted table of methods by CRAP score with risk levels, top offenders, quick wins, and the exact coverage needed to bring a method below the CRAP 15 threshold. - Use Case: Ask for the CRAP score of OrderService and receive a ranked list showing that ProcessOrder has complexity 12 and 45% coverage (CRAP 28.4, High risk), plus a recommendation to raise coverage to at least 72%. ## Quick Start Calculate the CRAP scores for all methods in OrderService.cs and tell me which ones need tests or refactoring 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 a .NET method?

Run dotnet test with Cobertura coverage collection, then compute cyclomatic complexity per method and apply the formula comp^2 * (1 - cov)^3 + comp. This Skill automates the full workflow for a named method, class, or file.

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, and above 30 is critical. A method with 100% coverage has a CRAP score equal to its cyclomatic complexity.

Does CRAP score analysis work with coverlet and Microsoft.Testing.Extensions.CodeCoverage?

Yes, both coverage collectors are supported. coverlet.collector uses --collect:"XPlat Code Coverage", while Microsoft.Testing.Extensions.CodeCoverage uses --coverage with cobertura output format, with slightly different syntax on .NET 9 versus .NET 10+.

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

Cobertura XML may use compiler-generated names for async methods, lambdas, and local functions. When names do not align, match methods by their line ranges in the coverage data instead of by name.

When should I not use CRAP score analysis?

Do not use it for project-wide coverage analysis, diagnosing coverage plateaus, or deciding where to add tests across a whole project. It targets a specific named method, class, or file, not broad coverage strategy.