@alxwlw/repo规则
从一个缺陷检查中得出的全库检查:每个缺陷都是一类缺陷,已经花费了一轮审查。 他们在CI和本地运行,在20号节点运行,没有依赖性.
pnpm add -D @alxwlw/repo-rules
pnpm exec repo-rules baseline --init # once: record what is already there
pnpm exec repo-rules check # every run: nothing new, nothing stale
pnpm exec repo-rules diff --base origin/main
repo-rules [-C <dir>] check [--json]
repo-rules [-C <dir>] diff [--base <ref>] [--json]
repo-rules [-C <dir>] baseline [--init] [--allow-grow]
-C <dir> 运行在目录中(存储库内的任何位置). --json 指纹 { violations, stale, notes } 而不是文本行. --help 打印用法; 缺少或未知的命令打印到 stderr 和 出道 2 上.
规则
| 规则 | 旗帜 |
|---|---|
max-lines | 一个800行以上的跟踪文本文件(计划、锁文件、JSON、快照、生成和销售文件除外) |
suppression-reason | eslint-disable* 编号 : oxlint-disable* 编号 : solhint-disable* 无 -- reason· ; @ts-expect-error 编号 : @ts-ignore 而不附带文字; biome-ignore 后面没有文本 :; 蟒蛇 # noqa 编号 : # type: ignore 无 -- reason |
focused-skipped-tests | 在JS/TS测试文件中: .only( 在任意一行上(扫描以行为主,见"限制"); .skip( 编号 : .todo( 编号 : xit( 编号 : xdescribe( 编号 : xtest( 无 -- reason 上行或上行评论. .skipIf 编号 : .runIf 和剧作家 test.skip(condition, reason) 没事 |
number-or-default | 在未测试的JS/TS文件中: Number(…), (中文(简体) ), Number.parseInt(…), (中文(简体) ), Number.parseFloat(…), (中文(简体) ), parseInt(…), (中文(简体) ), parseFloat(…) 接下来是 || <non-zero literal>: 一个真实的 0 默默成为默认值 |
removed-assertions (单位:千美元)diff(中文(简体) ) | 测试文件, diff 删除更多 expect( 编号 : assert… (c) 评论中的断言既不被删除也不被添加(评论确认: //, (中文(简体) ), /* … */ 在线上,一条线从 *· ; # 在 Python; 未关闭 /* 和从 * 隐藏该行的其余部分,包括后面的代码 */) (中文(简体) ). exclude (单位:千美元)* 或者说 removed-assertions适用。 A 类 Tests-Removed: <reason> 在射程内装拖车 |
原因至少有三个非空格字符.
基线
.repo-rules-baseline.json 记录已经存在的违规情况:每长文件行数,为其他规则按每个文件计数. check 当一个文件翻过其条目时失败, 以及当一个条目高于现实( stale)时, 因此一个固定位置不能被新位置重用 . baseline 只降低条目; 提高一个需要 --allow-grow显示在 PR diff 中.
配置
可选 .repo-rules.json数字 :
{
"maxLines": 800,
"exclude": { "*": ["public/vendor/**"], "max-lines": ["docs/*.html"] },
"testGlobs": [
"**/*.{test,spec}.*",
"**/__tests__/**",
"**/test/**",
"**/tests/**",
"**/*.t.sol",
"**/test_*.py",
"**/*_test.py"
]
}
testGlobs 替换上面全部显示的默认列表;不添加. exclude 带 * 或规则名称——上述四项规则和 removed-assertions。 。 。 .
限制
- 评论由一行heuristic,而不是一行解析器找到:regex文字或JSX文本中的引文可以在后一行隐藏指令.
<!-- -->注释.vue财务报告和审定财务报表.svelte文件不读取.number-or-default错过|| .5,则a||=默认应用到持有一个变量的变量Number(…)结果.removed-assertions不看到一个没有内容更改的重命名所禁用的测试( 例如)a.test.ts→a.test.ts.off) (中文(简体) ).removed-assertions在多行内读取一行/* … */块,不以*(例如重新缩进的)作为代码.- 请求移入已删除的助手数
Tests-Removed拖车是出路. - 扫描以行为主,不知道行是坐在字符串内还是模板字面,所以
.only(或者说.skip(在固定字符串中标出标记.
中情局
- uses: actions/checkout@v5
with:
fetch-depth: 0 # diff needs the merge-base
- run: pnpm exec repo-rules check
- run: pnpm exec repo-rules diff # base = origin/$GITHUB_BASE_REF in a pull_request job, skipped otherwise
出站代码:0 clean, 1 违规或 Stale 基线, 2 出站错误(从未读作干净).