.cursor/skills/crap-analysis/SKILL.md
Analyze code coverage and CRAP (Change Risk Anti-Patterns) scores to identify high-risk code. Use OpenCover format with ReportGenerator for Risk Hotspots showing cyclomatic complexity and untested code paths. Use when evaluating code quality and test coverage before changes, identifying high-risk code that needs refactoring or testing, setting up coverage collection for a .NET project, or establishing coverage thresholds for CI/CD pipelines.
npx skillsauth add AGIBuild/Fulora crap-analysisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when:
CRAP Score = Complexity x (1 - Coverage)^2
The CRAP (Change Risk Anti-Patterns) score combines cyclomatic complexity with test coverage to identify risky code.
| CRAP Score | Risk Level | Action Required | |------------|------------|-----------------| | < 5 | Low | Well-tested, maintainable code | | 5-30 | Medium | Acceptable but watch complexity | | > 30 | High | Needs tests or refactoring |
| Method | Complexity | Coverage | Calculation | CRAP |
|--------|------------|----------|-------------|------|
| GetUserId() | 1 | 0% | 1 x (1 - 0)^2 | 1 |
| ParseToken() | 54 | 52% | 54 x (1 - 0.52)^2 | 12.4 |
| ValidateForm() | 20 | 0% | 20 x (1 - 0)^2 | 20 |
| ProcessOrder() | 45 | 20% | 45 x (1 - 0.20)^2 | 28.8 |
| ImportData() | 80 | 10% | 80 x (1 - 0.10)^2 | 64.8 |
Create a coverage.runsettings file in your repository root. The OpenCover format is required for CRAP score calculation because it includes cyclomatic complexity metrics.
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<!-- OpenCover format includes cyclomatic complexity for CRAP scores -->
<Format>cobertura,opencover</Format>
<!-- Exclude test and benchmark assemblies -->
<Exclude>[*.Tests]*,[*.Benchmark]*,[*.Migrations]*</Exclude>
<!-- Exclude generated code, obsolete members, and explicit exclusions -->
<ExcludeByAttribute>Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute,ExcludeFromCodeCoverageAttribute</ExcludeByAttribute>
<!-- Exclude source-generated files, Blazor generated code, and migrations -->
<ExcludeByFile>**/obj/**/*,**/*.g.cs,**/*.designer.cs,**/*.razor.g.cs,**/*.razor.css.g.cs,**/Migrations/**/*</ExcludeByFile>
<!-- Exclude test projects -->
<IncludeTestAssembly>false</IncludeTestAssembly>
<!-- Optimization flags -->
<SingleHit>false</SingleHit>
<UseSourceLink>true</UseSourceLink>
<SkipAutoProps>true</SkipAutoProps>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
| Option | Purpose |
|--------|---------|
| Format | Must include opencover for complexity metrics |
| Exclude | Exclude test/benchmark assemblies by pattern |
| ExcludeByAttribute | Skip generated, obsolete, and explicitly excluded code (includes ExcludeFromCodeCoverageAttribute) |
| ExcludeByFile | Skip source-generated files, Blazor components, and migrations |
| SkipAutoProps | Don't count auto-properties as branches |
Install ReportGenerator as a local tool for generating HTML reports with Risk Hotspots.
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "5.4.5",
"commands": ["reportgenerator"],
"rollForward": false
}
}
}
Then restore:
dotnet tool restore
dotnet tool install --global dotnet-reportgenerator-globaltool
# Clean previous results
rm -rf coverage/ TestResults/
# Run unit tests with coverage
dotnet test tests/MyApp.Tests.Unit \
--settings coverage.runsettings \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults
# Run integration tests (optional, adds to coverage)
dotnet test tests/MyApp.Tests.Integration \
--settings coverage.runsettings \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults
dotnet reportgenerator \
-reports:"TestResults/**/coverage.opencover.xml" \
-targetdir:"coverage" \
-reporttypes:"Html;TextSummary;MarkdownSummaryGithub"
| Type | Description | Output |
|------|-------------|--------|
| Html | Full interactive report | coverage/index.html |
| TextSummary | Plain text summary | coverage/Summary.txt |
| MarkdownSummaryGithub | GitHub-compatible markdown | coverage/SummaryGithub.md |
| Badges | SVG badges for README | coverage/badge_*.svg |
| Cobertura | Merged Cobertura XML | coverage/Cobertura.xml |
The HTML report includes a Risk Hotspots section showing methods sorted by complexity:
Risk Hotspots
─────────────
Method Complexity Coverage Crap Score
──────────────────────────────────────────────────────────────────
DataImporter.ParseRecord() 54 52% 12.4
AuthService.ValidateToken() 32 0% 32.0 ← HIGH RISK
OrderProcessor.Calculate() 28 85% 1.3
UserService.CreateUser() 15 100% 0.0
Action items:
ValidateToken() has CRAP > 30 with 0% coverage - test immediately or refactorParseRecord() is complex but has decent coverage - acceptableCreateUser() and Calculate() are well-tested - safe to modify| Coverage Type | Target | Action | |---------------|--------|--------| | Line Coverage | > 80% | Good for most projects | | Branch Coverage | > 60% | Catches conditional logic | | CRAP Score | < 30 | Maximum for new code |
Create coverage.props in your repository:
<Project>
<PropertyGroup>
<!-- Coverage thresholds for CI enforcement -->
<CoverageThresholdLine>80</CoverageThresholdLine>
<CoverageThresholdBranch>60</CoverageThresholdBranch>
</PropertyGroup>
</Project>
name: Coverage
on:
pull_request:
branches: [main, dev]
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Restore tools
run: dotnet tool restore
- name: Run tests with coverage
run: |
dotnet test \
--settings coverage.runsettings \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults
- name: Generate report
run: |
dotnet reportgenerator \
-reports:"TestResults/**/coverage.opencover.xml" \
-targetdir:"coverage" \
-reporttypes:"Html;MarkdownSummaryGithub;Cobertura"
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
- name: Add coverage to PR
uses: marocchino/sticky-pull-request-comment@v2
with:
path: coverage/SummaryGithub.md
- task: DotNetCoreCLI@2
displayName: 'Run tests with coverage'
inputs:
command: 'test'
arguments: '--settings coverage.runsettings --collect:"XPlat Code Coverage" --results-directory $(Build.SourcesDirectory)/TestResults'
- task: DotNetCoreCLI@2
displayName: 'Generate coverage report'
inputs:
command: 'custom'
custom: 'reportgenerator'
arguments: '-reports:"$(Build.SourcesDirectory)/TestResults/**/coverage.opencover.xml" -targetdir:"$(Build.SourcesDirectory)/coverage" -reporttypes:"HtmlInline_AzurePipelines;Cobertura"'
- task: PublishCodeCoverageResults@2
displayName: 'Publish coverage'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/coverage/Cobertura.xml'
# Full analysis workflow
rm -rf coverage/ TestResults/ && \
dotnet test --settings coverage.runsettings \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults && \
dotnet reportgenerator \
-reports:"TestResults/**/coverage.opencover.xml" \
-targetdir:"coverage" \
-reporttypes:"Html;TextSummary"
# View summary
cat coverage/Summary.txt
# Open HTML report (Linux)
xdg-open coverage/index.html
# Open HTML report (macOS)
open coverage/index.html
# Open HTML report (Windows)
start coverage/index.html
| Metric | New Code | Legacy Code | |--------|----------|-------------| | Line Coverage | 80%+ | 60%+ (improve gradually) | | Branch Coverage | 60%+ | 40%+ (improve gradually) | | Maximum CRAP | 30 | Document exceptions | | High-risk methods | Must have tests | Add tests before modifying |
The recommended coverage.runsettings excludes:
| Pattern | Reason |
|---------|--------|
| [*.Tests]* | Test assemblies aren't production code |
| [*.Benchmark]* | Benchmark projects |
| [*.Migrations]* | Database migrations (generated) |
| GeneratedCodeAttribute | Source generators |
| CompilerGeneratedAttribute | Compiler-generated code |
| ExcludeFromCodeCoverageAttribute | Explicit developer opt-out |
| *.g.cs, *.designer.cs | Generated files |
| *.razor.g.cs | Blazor component generated code |
| *.razor.css.g.cs | Blazor CSS isolation generated code |
| **/Migrations/**/* | EF Core migrations (auto-generated) |
| SkipAutoProps | Auto-properties (trivial branches) |
Lower thresholds temporarily for:
Never lower thresholds for:
tools
Captures learnings, errors, and corrections to enable continuous improvement. Use when: (1) A command or operation fails unexpectedly, (2) User corrects Claude ('No, that's wrong...', 'Actually...'), (3) User requests a capability that doesn't exist, (4) An external API or tool fails, (5) Claude realizes its knowledge is outdated or incorrect, (6) A better approach is discovered for a recurring task. Also review learnings before major tasks.
testing
Security headers configuration and best practices for ASP.NET Core Razor Pages applications. Covers CSP, HSTS, X-Frame-Options, and comprehensive security middleware setup. Use when configuring security headers in ASP.NET Core applications, implementing Content Security Policy (CSP), or setting up HSTS and other security-related HTTP headers.
development
Reviews designs and business goals for security vulnerabilities, data protection (in transit/at rest), authorization, and compliance alignment. Use when the user asks for a security review, threat modeling, attack surface analysis, data leakage prevention, or compliance/security assessment.
development
Best practices for building production-grade ASP.NET Core Razor Pages applications. Focuses on structure, lifecycle, binding, validation, security, and maintainability in web apps using Razor Pages as the primary UI framework. Use when building Razor Pages applications, designing PageModels and handlers, implementing model binding and validation, or securing Razor Pages with authentication and authorization.