Repository navigation
Commit 7476fd0
committed
ci: 行数红线接入提交门禁与 CI
package.json 的 lint-staged 增加 "app/**/*.{ts,tsx,rs}": "node scripts/line-limits.mjs";
.github/workflows/pr-check.yml 新增无 needs/if 的 line-limits job,跑 node scripts/line-limits.mjs --full。
两个文件之外未改动任何内容,零新增依赖(dependencies / devDependencies 原样)。
两点行为说明(刻意如此,勿"优化"掉):
1. lint-staged 会附带暂存文件名,脚本予以忽略 —— 这是刻意的:漏登与棘轮都是全树性质,
只看暂存文件会漏。且 lint-staged 在部分暂存的情况下会把未暂存的改动 stash 起来再跑命令
⇒ 校验看到的是"即将提交的状态"(暂存文件 = 暂存内容,其余 = HEAD),不一定等于你编辑器
里的当前工作树。这是正确行为;若看到行数与眼前不符,先想这一点。
2. 跨平台行数一致:countLines 只数 \n,故 Windows 的 CRLF 工作树与 Linux 的 LF 检出对同一提交
得出相同行数("a\r\nb\r\n" 与 "a\nb\n" 都得 2)⇒ CI 的 --full 与本地提交门禁不会互相打架。
实测(非空转):
· 拦下:未登记的 app/src/__probe-lines.ts(320 行)暂存后提交被拒,exit=1、HEAD 未动,
lint-staged 报「(c) 超过 300 行但未登记:app/src/__probe-lines.ts(320 行)」,
末行「husky - pre-commit script failed (code 1)」;探针已删除,工作树复原。
· 放行:合规的 app/ 文件提交不被误拦(line-limits 默认校验 exit 0)。
环境注记:本克隆此前从未安装 husky(core.hooksPath 为空、无 node_modules),故本地门禁
在此之前对所有提交都是静默失效的;本次以 npm install + npm run prepare 激活后才取得上述
端到端拦截证据。他人克隆仍需先 npm install 才能让该门禁生效。1 parent 612a01c commit 7476fd0
2 files changed
Lines changed: 17 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
0 commit comments