@barney-media/crap-typescript
在TypeScript项目中用于CRAP(Change Risk Anti-Pattern)计量分析的CLI.
安装
npm install --save-dev @barney-media/crap-typescript
使用量
npx crap-typescript
npx crap-typescript --changed
npx crap-typescript --format json --output reports/crap.json
npx crap-typescript --agent --junit-report reports/crap-junit.xml
npx crap-typescript --threshold 6
npx crap-typescript --exclude 'packages/api/generated/**'
npx crap-typescript --exclude-path-regex '^src/proto/'
npx crap-typescript --exclude-generated-marker '@custom-generated'
npx crap-typescript src/sample.ts
npx crap-typescript packages/api packages/web
选项
--help Print usage to stdout
(no args) Analyze all TypeScript files under any nested src/ tree
--changed Analyze changed TypeScript files under src/
--exclude <glob> Exclude source paths by normalized relative glob; repeatable
--exclude-path-regex <regex> Exclude source paths by normalized relative regex; repeatable
--exclude-generated-marker <marker> Exclude leading generated-header markers; repeatable
--use-default-exclusions[=true|false] Enable generated-code defaults (`true` by default)
--package-manager <tool> Force auto, npm, pnpm, yarn, or bun
--test-runner <runner> Force auto, vitest, or jest
--format <format> Emit toon, json, text, junit, or none (default: toon)
--agent Default primary output to toon, failures-only, omit-redundancy
--failures-only[=true|false] Emit failed methods only in the primary report
--omit-redundancy[=true|false] Omit redundant per-method status in the primary report
--output <path> Write the primary report to a file instead of stdout
--junit-report <path> Also write a full JUnit XML report for CI test-report UIs
--threshold <number> Override the CRAP threshold (`6.0` by default)
<file ...> Analyze explicit TypeScript files
<directory ...> Analyze TypeScript files under each directory's nested src/ tree
默认 toon 格式是紧凑和代理可读的。 初步报告包括运行级别 status 财务报告和审定财务报表 threshold; 方法行使用 status, (中文(简体) ), crap, (中文(简体) ), cc, (中文(简体) ), cov, (中文(简体) ), covKind, (中文(简体) ), method, (中文(简体) ), src, (中文(简体) ), lineStart,以及 lineEnd,与 src 设置到项目相对源文件路径. --format none 压制主 stdout 输出; 当使用时 --output,它创建了空的主报告文件. --failures-only, (中文(简体) ), --failures-only=true,以及 --failures-only=false 控制主报告是否只包含失败的方法条目. --omit-redundancy, (中文(简体) ), --omit-redundancy=true,以及 --omit-redundancy=false 控制主报告方法行是否省略 status; 与 --format junit,它们省略了自定义测试框 status 属性,同时保留 JUnit 失败和跳出元素。 JUnit侧车报告总是包括全套方法集和方法状态,不论是否 --agent, (中文(简体) ), --failures-only,或 --omit-redundancy。JUnit XML是用于 GitLab 测试标签的形状,有一个 <testsuites> 包装、 测试 classname编号 :file 源路径, 带有度量的试样名称, time="0"级别 system-out 加上包含 CRAP 分数、阈值、覆盖类型、源路径和行距的失败/滑动文本. --agent 是一个复合快捷键,而不是格式:它默认主输出为 --format toon, (中文(简体) ), --failures-only=true,以及 --omit-redundancy=true明确 --format, (中文(简体) ), --failures-only=false,或 --omit-redundancy=false 选项可以覆盖这些默认值.
基线可分析性排除总是跳过声明,测试/样本文件, __tests__/, (中文(简体) ), dist/, (中文(简体) ), coverage/,以及 node_modules/生成代码默认值,然后排除生成的目录片段,精确 gen 目录片段,常见生成的文件名后缀,原出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自 除非 --use-default-exclusions=false; 禁用默认值不会禁用基线可分析性过滤器.
完整的初级报告和JUnit侧车在排除文件时包括排除来源的审计计数。 默认代理主输出省略了这些细节.
由内置执行人运行的命令,包括覆盖命令和 --changed 发现,300秒后暂停 设定 CRAP_TYPESCRIPT_COMMAND_TIMEOUT_MS 改为非负毫秒值,以覆盖这一默认值; 0 禁用超时。 被捕捉到的出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出 用户阵容命令失败可能包括截断输出,而需要完整输出的内部命令,例如 git status --porcelain -z,如果超过上限则失败.
默认阈值是 6.0。以下数值 4.0 打印警告,因为它们可能太吵;上方的值 8.0 印出警告,因为即使硬门也太宽大了.
退出代码
0成功,阈值得到遵守1无效的 CLI 使用或执行失败2CRAP 阈值超过 ( > 已配置阈值)
见 主要文件 详细情况.