基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/7Factor/crap4dotnet --skill crap命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | crap |
| description | Analyze C# code for CRAP (Change Risk Anti-Patterns) metrics using dotnet-crap |
| license | MIT |
| compatibility | Requires .NET 8.0+ SDK. The dotnet-crap global tool must be installed. |
| metadata | {"author":"7Factor","version":"0.1.0"} |
You have access to dotnet-crap, a .NET global tool that computes CRAP scores for C# code. CRAP combines cyclomatic complexity with code coverage to find methods that are both complex and poorly tested.
The tool is not yet published to NuGet. Install from source:
git clone <repo-url> && cd crap4dotnet
dotnet pack src/Crap4DotNet.Cli -o ./nupkg
dotnet tool install -g Crap4DotNet --add-source ./nupkg
Verify with dotnet-crap --version.
The simplest approach — let crap4dotnet run tests and generate coverage automatically:
dotnet-crap analyze <path> --run-tests
Or if the user already has Cobertura coverage files:
dotnet-crap analyze <path> --coverage <coverage-xml-path>
<path> can be a .cs file, directory, .csproj, or .sln (--run-tests requires .csproj, .sln, or directory)--run-tests runs dotnet test with coverage collection automatically (mutually exclusive with --coverage)--coverage accepts one or more Cobertura XML paths (globs work)--threshold <n> sets the CRAP threshold (default: 30)--min-crap <n> filters out low-scoring methods from output--output <path> writes JSON to a file instead of stdoutThe tool outputs JSON to stdout. Key fields:
stats.crappyMethodCount — number of methods exceeding the thresholdstats.averageCrap — project-wide average CRAP scoremethods[] — array of per-method results, each with:
fullName — fully qualified method namefilePath and lineNumber — source location (navigate directly)crap — the CRAP scorecomplexity — cyclomatic complexitycoverage — code coverage (0.0 to 1.0)isCrappy — whether it exceeds the thresholdseverity — one of: low, moderate, elevated, high, criticalSummarize findings for the user:
To track changes over time:
dotnet-crap diff <before.json> <after.json>
The diff output classifies methods as: added, removed, new_crappy, fixed, regressed, improved. Focus on new_crappy (newly risky) and fixed (wins to celebrate).
| CRAP Score | Severity | Action |
|---|---|---|
| 1 – 5 | Low | No action needed |
| 6 – 15 | Moderate | Consider adding tests |
| 16 – 30 | Elevated | Prioritize test coverage |
| 31 – 60 | High | Refactor and/or add tests |
| 60+ | Critical | Urgent refactoring required |
A method with complexity >= 31 is always CRAPpy regardless of coverage, because CRAP(31, 1.0) = 31 > 30. For these methods, the only fix is reducing complexity through refactoring.