Token导航 LogoToken导航TokenDH.com
研究检索权限需确认github未标认证来源可访问许可证需确认审计通过

crap-score废话分数

Agent Skill

crap-score 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

4,284

周安装

184

GitHub Stars

1,465

下载量

1,501
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:crap-score(废话分数)
来源仓库:https://github.com/dotnet/skills
仓库路径:skills/crap-score
安装命令:
npx skills add https://github.com/dotnet/skills --skill crap-score
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dotnet/skills --skill crap-score

简介

crap-score 计算 .NET 方法的 CRAP 分数,综合圈复杂度和测试覆盖率识别潜在风险代码。

  • 适用于代码评审、重构优先级排序及测试资源分配等质量保障场景。
  • 根据分数区间提供风险解读和改进方向,支持建立自动化质量阈值规则。
  • 需配合代码覆盖率工具使用,确保数据准确反映实际测试执行情况。
  • crap-score 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

CRAP Score Analysis

Calculate CRAP (Change Risk Anti-Patterns) scores for.NET methods to identify code that is both complex and undertested.

Background

The CRAP score combines cyclomatic complexity and code coverage into a single metric:

$$\text{CRAP}(m) = \text{comp}(m)^2 \times (1 - \text{cov}(m))^3 + \text{comp}(m)$$

Where:

  • $\text{comp}(m)$ = cyclomatic complexity of method $m$
  • $\text{cov}(m)$ = code coverage ratio (0.0 to 1.0) of method $m$
CRAP ScoreRisk LevelInterpretation
< 5LowSimple and well-tested
5-15ModerateAcceptable for most code
15-30HighNeeds more tests or simplification
> 30CriticalRefactor and add coverage urgently

A method with 100% coverage has CRAP = complexity (the minimum). A method with 0% coverage has CRAP = complexity^2 + complexity.

When to Use

  • User wants to assess which methods are risky due to low coverage and high complexity
  • User asks for CRAP score of specific methods, classes, or files
  • User wants to prioritize which code to test next
  • User wants to evaluate test quality beyond simple coverage percentages

When Not to Use

  • User just wants to run tests (use run-tests skill)
  • User wants to write new tests (use writing-mstest-tests skill or general coding assistance)
  • User only wants a coverage percentage without complexity analysis

Inputs

InputRequiredDescription
Target scopeYesMethod name, class name, or file path to analyze
Test project pathNoPath to the test project. Defaults to discovering test projects in the solution.
Source project pathNoPath to the source project under analysis

Workflow

Step 1: Collect code coverage data

If no coverage data exists yet (no Cobertura XML available), always run dotnet test with coverage collection first and mention the exact command in your response. Do not skip this step -- CRAP scores require coverage data.

Check the test project's .csproj for the coverage package, then run the appropriate command:

Coverage PackageCommandOutput Location
coverlet.collectordotnet test --collect:"XPlat Code Coverage" --results-directory./TestResultsTypically under TestResults/<guid>/coverage.cobertura.xml. Search recursively under the results directory (for example, TestResults/**/coverage.cobertura.xml) or use any explicit coverage path the user provides.
Microsoft.Testing.Extensions.CodeCoverage (.NET 9)dotnet test -- --coverage --coverage-output-format cobertura --coverage-output./TestResults--coverage-output path
Microsoft.Testing.Extensions.CodeCoverage (.NET 10+)dotnet test --coverage --coverage-output-format cobertura --coverage-output./TestResults--coverage-output path

Step 2: Compute cyclomatic complexity

Analyze the target source files to determine cyclomatic complexity per method. Count the following decision points (each adds 1 to the base complexity of 1):

ConstructExample
ifif (x > 0)
else ifelse if (y < 0)
case (each)case 1:
forfor (int i = 0;...)
foreachforeach (var item in list)
whilewhile (running)
do...whiledo {} while (cond)
catch (each)catch (Exception ex)
&&if (a && b)
`\\` (OR)`if (a \\b)`
??value?? fallback
?.obj?.Method()
?: (ternary)x > 0? a: b
Pattern match armx is > 0 and < 10

Base complexity is 1 for every method. Each decision point adds 1.

When analyzing, read the source file and count these constructs per method. Report the breakdown.

Step 3: Extract per-method coverage from Cobertura XML

Parse the Cobertura XML to find each method's line-rate attribute under the target <class> element. If line-rate is not available at method level, compute it from the <lines> elements:

$$\text{cov}(m) = \frac{\text{lines with hits} > 0}{\text{total lines}}$$

Method names in Cobertura may differ from source (async methods, lambdas). Match by line ranges when names don't align.

Step 4: Calculate CRAP scores

For each method in scope, apply the formula:

$$\text{CRAP}(m) = \text{comp}(m)^2 \times (1 - \text{cov}(m))^3 + \text{comp}(m)$$

Step 5: Present results

Present a sorted table (highest CRAP first):

| Method                          | Complexity | Coverage | CRAP Score | Risk     |
|---------------------------------|------------|----------|------------|----------|
| OrderService.ProcessOrder       | 12         | 45%      | 28.4       | High     |
| OrderService.ValidateItems      | 8          | 90%      | 8.1        | Moderate |
| OrderService.CalculateTotal     | 3          | 100%     | 3.0        | Low      |

Include:

  • Summary: total methods analyzed, how many in each risk category
  • Top offenders: methods with CRAP > 30, with specific recommendations
  • Quick wins: methods with high complexity but where small coverage improvements would drop the score significantly

Step 6: Provide actionable recommendations

For high-CRAP methods, suggest one or both:

  1. Add tests -- identify uncovered branches and suggest specific test cases
  2. Reduce complexity -- suggest extract-method refactoring for deeply nested logic

Calculate the coverage needed to bring a method below a CRAP threshold of 15:

$$\text{cov}_{\text{needed}} = 1 - \left(\frac{15 - \text{comp}}{\text{comp}^2}\right)^{1/3}$$

This formula only applies when comp < 15. When comp >= 15, the minimum possible CRAP score (at 100% coverage) is comp itself, which already meets or exceeds the threshold. In that case, coverage alone cannot bring the CRAP score below the threshold -- the method must be refactored to reduce its cyclomatic complexity first.

Report this as: "To bring ProcessOrder (complexity 12) below CRAP 15, increase coverage from 45% to at least 72%." For methods where complexity alone exceeds the threshold, report: "ComplexMethod (complexity 18) cannot reach CRAP < 15 through testing alone -- reduce complexity by extracting sub-methods."

Validation

  • Verify that coverage data was collected successfully (Cobertura XML exists and contains data)
  • Cross-check that method names in coverage data match the source code
  • Confirm CRAP scores by spot-checking the formula on one method manually
  • Ensure a 100%-covered method's CRAP equals its complexity exactly

Common Pitfalls

  • Stale coverage data: Always regenerate coverage before computing CRAP scores. Old coverage files will produce misleading results.
  • Method name mismatches: Cobertura XML may use mangled/compiler-generated names for async methods, lambdas, or local functions. Match by line ranges when names don't align.
  • Generated code: Exclude auto-generated files (e.g., *.Designer.cs, *.g.cs) from analysis unless explicitly requested.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.93%
按下载量换算569

Claude

29.49%
按下载量换算443

Cursor

19.6%
按下载量换算294

Gemini CLI

8.48%
按下载量换算127

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

权限需确认

当前来源未能明确判断权限范围,默认进入异常复核队列。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills