crap-score

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

Updated Jul 2, 2026
One-click install
npx skills add https://github.com/ecoDriverltd/FoundryAgentsExperiment --skill crap-score-ecodriverltd
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: crap-score
Source: https://github.com/ecoDriverltd/FoundryAgentsExperiment/tree/main/.agents/skills/crap-score
Command: npx skills add https://github.com/ecoDriverltd/FoundryAgentsExperiment --skill crap-score-ecodriverltd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Identifying which .NET methods are both complex and undertested is difficult when looking at coverage percentages or complexity metrics in isolation. This Skill computes CRAP (Change Risk Anti-Patterns) scores to pinpoint risky code that needs tests or refactoring first. ## Core Features & Use Cases - CRAP Score Calculation: Combines cyclomatic complexity with Cobertura line coverage using the standard CRAP formula to rank methods by risk. - 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 generate fresh Cobertura XML. - Actionable Recommendations: Reports risk tiers, top offenders, quick wins, and the exact coverage needed to bring a method below a CRAP threshold, or flags methods that must be refactored first. - Use Case: Ask for the CRAP score of OrderService.cs to get a sorted table showing which methods have high complexity and low coverage, plus specific suggestions for test cases or extract-method refactors. ## Quick Start Calculate the CRAP scores for all methods in OrderService.cs using coverage from my test project.

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 scores for C# methods?▼

Run dotnet test with coverage collection to produce a Cobertura XML report, then compute cyclomatic complexity per method and apply the CRAP formula: complexity squared times (1 minus coverage) cubed, plus complexity. This Skill automates the full workflow.

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.

Which coverage tools work with CRAP score analysis in .NET?▼

The analysis works with Cobertura XML output from coverlet.collector via the XPlat Code Coverage collector, or from Microsoft.Testing.Extensions.CodeCoverage on .NET 9 and later using the --coverage-output-format cobertura flag.

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 report instead of by name.

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 be refactored, for example by extracting sub-methods, to reduce complexity first.

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 solution. It is designed for targeted analysis of a named method, class, or single source file, not broad coverage strategy.