focus-guard 3.5.2 → 3.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/README.zh-CN.md +14 -4
- package/assets/NOTICE.md +3 -1
- package/docs/ARCH-MAP.md +302 -74
- package/docs/BENCH.md +28 -13
- package/docs/RELEASE-POLICY.md +74 -17
- package/docs/RULES.md +98 -60
- package/docs/THREAT-MODEL.md +3 -3
- package/docs/WRITING-STYLE.md +40 -2
- package/package.json +11 -5
- package/skills/focus-plan/SKILL.md +77 -0
- package/skills/focus-rules/SKILL.md +267 -0
- package/skills/focus-thinking/SKILL.md +8 -255
- package/src/adapters/dsh/eligibility-gate.mjs +75 -35
- package/src/adapters/dsh/session.mjs +22 -0
- package/src/{dsh → adapters/dsh}/toolName.mjs +6 -0
- package/src/core/approvals.mjs +10 -4
- package/src/core/audit-writer.mjs +5 -2
- package/src/core/auditActions.mjs +214 -0
- package/src/core/checkEligibility.mjs +193 -130
- package/src/core/constants.mjs +8 -4
- package/src/core/decisionEngine.mjs +16 -13
- package/src/core/env.mjs +37 -2
- package/src/core/patterns.mjs +3 -1
- package/src/core/prefixStability.mjs +27 -3
- package/src/core/profileLoader.mjs +96 -3
- package/src/core/scratch.mjs +288 -0
- package/src/core/session.mjs +23 -0
- package/src/core/state.mjs +3 -3
- package/src/dsh/audit.mjs +45 -170
- package/src/dsh/bridgeCheck.mjs +81 -0
- package/src/dsh/compactionWatch/announce.mjs +2 -1
- package/src/dsh/compactionWatch.mjs +2 -1
- package/src/dsh/cost-ledger.mjs +174 -0
- package/src/dsh/guard/authz.mjs +3 -3
- package/src/dsh/guard/evidence.mjs +19 -0
- package/src/dsh/guard/retryGuard.mjs +96 -0
- package/src/dsh/guard/risk.mjs +61 -16
- package/src/dsh/guard/tooling.mjs +20 -13
- package/src/dsh/{value-gate.mjs → guard/value-gate.mjs} +6 -0
- package/src/dsh/guard/writing-gate.mjs +117 -0
- package/src/dsh/index.js +4 -7
- package/src/dsh/pipeline.mjs +72 -8
- package/src/dsh/postProgress.mjs +81 -40
- package/src/dsh/preGuard.mjs +12 -3
- package/src/dsh/repeatGuard.mjs +5 -4
- package/src/dsh/seams/pre-step.mjs +74 -23
- package/src/dsh/seams/prompt-rules.mjs +91 -5
- package/src/dsh/{guard → seams}/runtime.mjs +41 -10
- package/src/dsh/seams/session-start.mjs +33 -10
- package/src/dsh/seams/shared.mjs +8 -5
- package/src/dsh/search-hints.mjs +15 -1
- package/src/dsh/sessionScope.mjs +11 -11
- package/src/dsh/stopGuard.mjs +2 -7
- package/src/dsh/tools.mjs +39 -1
- package/src/dsh/traceMeta.mjs +5 -11
- package/src/memory/index.mjs +7 -5
- package/src/memory/workspace.mjs +41 -19
- package/src/profiles/deepseek-flash.mjs +10 -8
- package/src/profiles/deepseek-pro.mjs +9 -8
- package/src/profiles/default.mjs +14 -8
- package/src/profiles/glm.mjs +9 -8
- package/src/profiles/gpt-astra.mjs +11 -9
- package/tools/audit-chain.mjs +29 -4
- package/tools/collect-panel.mjs +3 -24
- package/tools/dead-export.mjs +2 -17
- package/tools/docs-book.mjs +234 -0
- package/tools/docs-drift.mjs +143 -0
- package/tools/docs-lint.mjs +76 -9
- package/tools/docs-refs.mjs +343 -0
- package/tools/gate-audit.mjs +3 -24
- package/tools/handoff.mjs +4 -2
- package/tools/index-stale.mjs +124 -0
- package/tools/install-check.mjs +107 -9
- package/tools/knowledge.mjs +53 -4
- package/tools/layering-audit.mjs +7 -1
- package/tools/legacy-audit.mjs +83 -0
- package/tools/lib/book-style.mjs +42 -1
- package/tools/lib/case-tool.mjs +9 -3
- package/tools/lib/cli.mjs +35 -0
- package/tools/lib/docs-ack.mjs +97 -0
- package/tools/lib/docs-core.mjs +84 -45
- package/tools/lib/docs-files.mjs +73 -0
- package/tools/lib/docs-scope.mjs +46 -0
- package/tools/lib/docs-status.mjs +148 -0
- package/tools/lib/docs-typography.mjs +91 -0
- package/tools/lib/docs-version.mjs +8 -5
- package/tools/lib/dup-block.mjs +117 -0
- package/tools/lib/idioms.mjs +149 -0
- package/tools/lib/import-graph.mjs +8 -3
- package/tools/lib/index-io.mjs +4 -4
- package/tools/lib/index-registry.mjs +101 -0
- package/tools/lib/legacy-core.mjs +178 -0
- package/tools/lib/markdown.mjs +202 -0
- package/tools/lib/modules-doc.mjs +103 -0
- package/tools/lib/modules-list.mjs +396 -0
- package/tools/lib/modules.mjs +360 -0
- package/tools/lib/mutation-ops.mjs +63 -0
- package/tools/lib/parse-block.mjs +58 -0
- package/tools/lib/prefix-cost.mjs +5 -3
- package/tools/lib/ratchet.mjs +22 -8
- package/tools/lib/release-faces.mjs +144 -0
- package/tools/lib/repo-copy.mjs +34 -0
- package/tools/lib/survey-report.mjs +57 -0
- package/tools/lib/where.mjs +139 -0
- package/tools/library-book.mjs +7 -92
- package/tools/library-build.mjs +15 -3
- package/tools/lint.mjs +24 -13
- package/tools/log-audit.mjs +76 -0
- package/tools/memory-audit.mjs +32 -6
- package/tools/memory-distill.mjs +14 -1
- package/tools/memory-recall-eval.mjs +408 -0
- package/tools/module-audit.mjs +2 -17
- package/tools/modules-audit.mjs +110 -0
- package/tools/mutate.mjs +120 -74
- package/tools/panel-baseline.mjs +172 -0
- package/tools/prefix-audit.mjs +10 -2
- package/tools/prefix-drift.mjs +10 -5
- package/tools/registry-check.mjs +200 -0
- package/tools/release.mjs +322 -0
- package/tools/smells.mjs +97 -139
- package/tools/version.mjs +12 -8
- package/docs/AB-PROMPTS.md +0 -123
- package/docs/AB-SESSION.md +0 -161
- package/docs/BENCH-BASELINE.json +0 -95
- package/docs/BRAIN-VIZ.md +0 -94
- package/docs/GATE-INPUTS.json +0 -10
- package/docs/HANDOFF-2026-10-27.md +0 -736
- package/docs/HOOK-ORDERING.md +0 -139
- package/docs/LEGISLATION-LAW.md +0 -104
- package/docs/MCP-4.0-PLAN.md +0 -184
- package/docs/MEMORY-4.5-PLAN.md +0 -415
- package/docs/PROFILE-TUNING.md +0 -147
- package/docs/RATCHET.json +0 -80
- package/docs/TOOL-SCHEMA.json +0 -6
- package/docs/VERSION-PLAN.md +0 -604
- package/docs/architecture-map.mermaid +0 -186
- package/docs/deepseek-pricing-audit.md +0 -65
- package/src/core/staleCleanup.mjs +0 -224
- package/src/dsh/guard/superpowers.mjs +0 -70
- package/src/dsh/workspace.mjs +0 -5
- package/tools/library-index.mjs +0 -91
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 产物面:`npm run release:status` 要问的四个独立真值。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单列一个文件:这四面的探测各有各的坑(gh 的字段名、jq 输出为空、一次发布横跨多个运行),
|
|
5
|
+
* 注释比代码长,塞在 `release.mjs` 里把它顶到 402 行、越了 400 的行数阈值。
|
|
6
|
+
* 按仓库规矩**只许拆不许抬**,于是拆出来。
|
|
7
|
+
*
|
|
8
|
+
* 从 `release.mjs` 拆出的原因记录在 CHANGELOG(`refactor(tools)`),这里只保留机制说明。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { execFileSync } from 'node:child_process'
|
|
12
|
+
import { readFileSync } from 'node:fs'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
import { probeVersion, registryBase } from '../registry-check.mjs'
|
|
15
|
+
|
|
16
|
+
const git = (root, args) => (execFileSync('git', args, { cwd: root, encoding: 'utf8' }) || '').trim()
|
|
17
|
+
|
|
18
|
+
/** 包名:探 registry 用,与版本同源(`packages/core/package.json`)。 */
|
|
19
|
+
export function packageName(root) {
|
|
20
|
+
return JSON.parse(readFileSync(join(root, 'packages/core/package.json'), 'utf8')).name
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 最近一次 publish 运行;没装 gh / 未登录 / 从没跑过都返回 null。
|
|
25
|
+
*
|
|
26
|
+
* 2026-11-26 修两处,都是「认领哪一次运行」的坑:
|
|
27
|
+
* 1. `gh workflow run --ref main` 手动补发时 displayTitle 只有「publish」、headBranch 是 main,
|
|
28
|
+
* 按 tag 名怎么都认不出来——旧实现于是退到上一次历史运行,`--status` 永远指着那条失败报红。
|
|
29
|
+
* 2. 一次版本发布可能横跨多个 run(先跑失败 → 重跑成功 → 补 Release 又一条),
|
|
30
|
+
* 按 tag 名 `find` 拿到的是**最早**那条。现在取时间最新的一条,另给 `related` 标明它是否与
|
|
31
|
+
* 这个 tag 精确对应;不对应就只是线索,不当判据。
|
|
32
|
+
*/
|
|
33
|
+
export function publishRun(root, tag, sinceMs = 0, commit = null) {
|
|
34
|
+
try {
|
|
35
|
+
const out = execFileSync('gh', ['run', 'list', '--workflow=publish.yml', '--limit', '20', '--json', 'displayTitle,headBranch,headSha,status,conclusion,url,createdAt'], {
|
|
36
|
+
cwd: root,
|
|
37
|
+
encoding: 'utf8',
|
|
38
|
+
})
|
|
39
|
+
// gh 按时间倒序;`sinceMs` 用来排除同一 tag 的历史运行(失败重跑时最容易被误当成「刚触发的」)。
|
|
40
|
+
const fresh = (r) => !sinceMs || Date.now() - new Date(r.createdAt).getTime() <= sinceMs
|
|
41
|
+
const runs = JSON.parse(out).filter(fresh)
|
|
42
|
+
const latest = runs[0]
|
|
43
|
+
if (!latest) return null
|
|
44
|
+
const related = (r) => (r.displayTitle || '').includes(tag) || r.headBranch === tag || Boolean(commit && r.headSha === commit)
|
|
45
|
+
return { ...latest, related: related(latest), everRelated: runs.some(related) }
|
|
46
|
+
} catch {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** tag 的本地 / 远端 / Release / 是否 Latest 四个值,各自独立取,缺哪个说哪个。 */
|
|
52
|
+
export function githubFace(root, tag) {
|
|
53
|
+
const tryGit = (args) => {
|
|
54
|
+
try {
|
|
55
|
+
return git(root, args)
|
|
56
|
+
} catch {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const head = tryGit(['rev-parse', 'HEAD'])
|
|
61
|
+
const local = tryGit(['rev-parse', `refs/tags/${tag}`])
|
|
62
|
+
const commit = tryGit(['rev-parse', `refs/tags/${tag}^{commit}`])
|
|
63
|
+
const remote = (() => {
|
|
64
|
+
const all = tryGit(['ls-remote', '--tags', 'origin'])
|
|
65
|
+
if (!all) return null
|
|
66
|
+
const line = all.split('\n').find((l) => l.endsWith(`refs/tags/${tag}`))
|
|
67
|
+
return line ? line.split(/\s+/)[0] : null
|
|
68
|
+
})()
|
|
69
|
+
let release = null
|
|
70
|
+
try {
|
|
71
|
+
// 不用 `--json isLatest`:gh 的字段随版本增减,2.6x 上根本没有它(实测报 Unknown JSON field)。
|
|
72
|
+
// 「是不是 Latest」另走一个权威口:`releases/latest`,那是 GitHub 自己认的那一个。
|
|
73
|
+
release = JSON.parse(execFileSync('gh', ['release', 'view', tag, '--json', 'tagName,createdAt,isDraft,isPrerelease'], { cwd: root, encoding: 'utf8' }))
|
|
74
|
+
// `gh api` 返回的是**原始** API 字段(snake_case),与 `gh release view --json` 的驼峰不同;
|
|
75
|
+
// 且本机 gh 的 `--jq` 输出为空(实测只有换行),所以自己解析、认 `tag_name`。
|
|
76
|
+
const latest = JSON.parse(execFileSync('gh', ['api', 'repos/{owner}/{repo}/releases/latest'], { cwd: root, encoding: 'utf8' }))
|
|
77
|
+
release.isLatest = latest?.tag_name === tag
|
|
78
|
+
} catch {
|
|
79
|
+
release = null
|
|
80
|
+
}
|
|
81
|
+
return { head, local, commit, remote, atHead: Boolean(commit && head && commit === head), release }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const mark = (ok) => (ok ? '✅' : '❌')
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 四个真值各取一次,返回可直接打印的行与结论。
|
|
88
|
+
* 结论只看 **tag / Release / registry** 三面——workflow 面只作线索(它能红在发布之后的确认步骤上,
|
|
89
|
+
* 也可能一次发布横跨多个 run,拿它判红会每发一版留一条假红)。
|
|
90
|
+
*/
|
|
91
|
+
export async function productStatus({ root, version, tag }) {
|
|
92
|
+
// 先把 registry 探测发出去(异步),再跑几个 execFileSync 的活——它们的等待正好被 fetch 用掉。
|
|
93
|
+
// `elapsed` 只算探测本身(从发出到拿回),不含被 gh 那几条命令占用的时间。
|
|
94
|
+
const t0 = Date.now()
|
|
95
|
+
const registryProbe = probeVersion(registryBase(), packageName(root), version)
|
|
96
|
+
.then((r) => ({ ...r, elapsed: Date.now() - t0 }))
|
|
97
|
+
.catch((err) => ({ state: 'error', detail: err.message, elapsed: Date.now() - t0 }))
|
|
98
|
+
const gh = githubFace(root, tag)
|
|
99
|
+
const run = publishRun(root, tag, 0, gh.commit)
|
|
100
|
+
const registry = await registryProbe
|
|
101
|
+
const published = registry.state === 'present'
|
|
102
|
+
// 「tag 合格」只要求**本地与远端是同一个对象**。是否指向 HEAD 单独说:
|
|
103
|
+
// 发完之后必然还要回填 README / `PUBLISHED_MAX` 那几处(政策 §四 第 8 步),
|
|
104
|
+
// 于是 tag 正常会落后 HEAD 一两个提交——把它算成 ❌,等于每发一版就留一条假红。
|
|
105
|
+
const tagOk = Boolean(gh.local && gh.remote && gh.local === gh.remote)
|
|
106
|
+
const lines = []
|
|
107
|
+
lines.push(` tag ${mark(tagOk)} ${tag}${tagOk ? '(本地=远端)' : ''}`)
|
|
108
|
+
if (!tagOk) {
|
|
109
|
+
if (!gh.local) lines.push(' 本地没有这个 tag')
|
|
110
|
+
else if (!gh.remote) lines.push(` 远端没有这个 tag——\`git push origin ${tag}\``)
|
|
111
|
+
else lines.push(' 远端与本地不是同一个对象——同版本不重打,先确认该保留哪个')
|
|
112
|
+
} else if (gh.commit && !gh.atHead) {
|
|
113
|
+
lines.push(` ℹ tag 指向 ${String(gh.commit).slice(0, 7)},HEAD 是 ${String(gh.head).slice(0, 7)}(发布后回填文档属正常)`)
|
|
114
|
+
}
|
|
115
|
+
lines.push(` Release ${mark(Boolean(gh.release))} ${gh.release ? `${gh.release.tagName}${gh.release.isLatest ? '(Latest)' : ''}` : '没有'}`)
|
|
116
|
+
lines.push(
|
|
117
|
+
` registry ${mark(published)} ${
|
|
118
|
+
published ? `${version} 已发布(${(registry.elapsed / 1000).toFixed(1)}s 读到版本文档)` : registry.state === 'error' ? `查不了(${registry.detail})` : `未见 ${version}`
|
|
119
|
+
}`,
|
|
120
|
+
)
|
|
121
|
+
// workflow 面只作线索,不参与结论。理由:它能红在「发布之后」的确认步骤上(3.5.3 那次就是
|
|
122
|
+
// ——npm 已收下、Release 已建,红在 Verify 的判据),而一次版本发布又可能横跨多个 run
|
|
123
|
+
// (失败 → 重跑成功 → 补 Release)。所以这一行说清「哪条运行、跟这个 tag 对不对应」,
|
|
124
|
+
// 让结论由前三面给,不拿运行记录去覆盖产物事实。
|
|
125
|
+
let workflowLine
|
|
126
|
+
if (!run) workflowLine = ' workflow ℹ (没有 gh 或没跑过——跳过)'
|
|
127
|
+
else {
|
|
128
|
+
const state = run.status === 'completed' ? run.conclusion : run.status
|
|
129
|
+
const icon = run.status !== 'completed' ? '⏳' : 'ℹ'
|
|
130
|
+
const how = run.related ? '与 tag 精确对应' : run.everRelated ? '最新一条;同版本另有更早的运行' : '最新一条;与 tag 无对应关系'
|
|
131
|
+
workflowLine = ` workflow ${icon} ${state} · ${run.url}\n ${how}:${run.displayTitle || '(无标题)'} @ ${String(run.headSha || '').slice(0, 7)}`
|
|
132
|
+
}
|
|
133
|
+
lines.push(workflowLine)
|
|
134
|
+
let verdict
|
|
135
|
+
// 「查不了」与「没有」必须分开说。合并成一句「未发布」是最坏的一种——2026-11-26 本机一次
|
|
136
|
+
// 网络瞬断就让它报了「还没有 publish 运行」,而三面其实齐平。查不了不等于没发过。
|
|
137
|
+
if (published && gh.release && tagOk) verdict = '已发布:tag / Release / npm 三面齐平'
|
|
138
|
+
else if (published) verdict = 'npm 上有了,但 GitHub 面不齐——按上面 ❌ 补'
|
|
139
|
+
else if (registry.state === 'error') verdict = `查不了:registry 不可达(${registry.detail})——这不等于没发布,联网后重跑本命令`
|
|
140
|
+
else if (run && run.status !== 'completed') verdict = `发布中(${run.status}),不用守着:稍后重跑本命令`
|
|
141
|
+
else if (run && run.conclusion === 'failure') verdict = '未发布:工作流失败,先看日志再重跑'
|
|
142
|
+
else verdict = '未发布:还没有 publish 运行'
|
|
143
|
+
return { lines, verdict, published, tagOk }
|
|
144
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 仓根副本(2026-11-27,3.5.4 从 tools/mutate.mjs 抽出)。
|
|
3
|
+
*
|
|
4
|
+
* 抽出的理由:mutate.mjs 撞 400 行阈值;这段只做「复制」,与变异逻辑无关。
|
|
5
|
+
*/
|
|
6
|
+
import { cpSync, readdirSync } from "node:fs"
|
|
7
|
+
import { join } from "node:path"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 副本黑名单(2026-11-27,3.5.4)。
|
|
11
|
+
*
|
|
12
|
+
* 原先是白名单:只复制 `packages/` 与 `package.json`。代价是**每新增一个顶层目录就静默漏一次**。
|
|
13
|
+
* 测试一旦引用仓根的东西(`docs/` 下的法典、`CHANGELOG.md`、`.git` 历史),基线就红,
|
|
14
|
+
* 而红的原因只报「基线测试未通过」——看不出是副本缺文件。实测 `core/risk.mjs` 因此 30 条用例失败。
|
|
15
|
+
*
|
|
16
|
+
* 改黑名单:除下列目录外全复制。新增顶层目录自动进副本,不需要回来改这里。
|
|
17
|
+
* 排除的都是「本机状态」或「体积大且与判定无关」:`node_modules` 可由包自身解析,
|
|
18
|
+
* `.focus-guard` / `.ai` 是运行时会写的东西,复制进去只会让隔离测试互相污染。
|
|
19
|
+
*/
|
|
20
|
+
const COPY_SKIP = new Set(['node_modules', '.focus-guard', '.ai', '.archify', 'coverage', 'dist', '.vs'])
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 把仓根复制成临时副本。逐顶层条目复制而不是 `cpSync(REPO, work)`——
|
|
24
|
+
* 后者在目标目录已存在时的落点规则依赖实现细节,不如显式列出来得可靠。
|
|
25
|
+
*
|
|
26
|
+
* `repo` 可传:用例要拿一个受控夹具证明「新增顶层目录自动进副本」,
|
|
27
|
+
* 而模块级的 `REPO` 是常量,不参数化就只能去改真实仓库来测。**能指到别处才测得了。**
|
|
28
|
+
*/
|
|
29
|
+
export function copyRepo(repo, dest) {
|
|
30
|
+
for (const entry of readdirSync(repo, { withFileTypes: true })) {
|
|
31
|
+
if (COPY_SKIP.has(entry.name)) continue
|
|
32
|
+
cpSync(join(repo, entry.name), join(dest, entry.name), { recursive: true })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 抽样汇总与分片派发(2026-11-27,3.5.4 从 tools/mutate.mjs 抽出)。
|
|
3
|
+
*
|
|
4
|
+
* `self` 与 `repo` 走参数:搬进 lib/ 之后 `import.meta.url` 指向 lib 自己,
|
|
5
|
+
* 而子进程必须重启**入口脚本**,不能指向这里。
|
|
6
|
+
*/
|
|
7
|
+
import { spawn } from "node:child_process"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 起 `jobs` 个分片子进程,合并结果。
|
|
11
|
+
*
|
|
12
|
+
* 为什么不是 worker_threads:被测的是子进程(`node --test`),线程里再 spawn 进程
|
|
13
|
+
* 没有任何收益,反而多一层共享状态。
|
|
14
|
+
*/
|
|
15
|
+
export async function surveyParallel({ jobs, self, repo }) {
|
|
16
|
+
const runs = Array.from({ length: jobs }, (_, i) => {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const cp = spawn('node', [self, '--survey', '--shard', `${i}/${jobs}`], {
|
|
19
|
+
cwd: repo,
|
|
20
|
+
env: process.env,
|
|
21
|
+
})
|
|
22
|
+
let out = ''
|
|
23
|
+
cp.stdout.on('data', (d) => {
|
|
24
|
+
out += d
|
|
25
|
+
})
|
|
26
|
+
cp.stderr.on('data', (d) => process.stderr.write(d))
|
|
27
|
+
cp.on('close', () => {
|
|
28
|
+
const m = out.match(/__ROWS__([\s\S]*)$/)
|
|
29
|
+
if (!m) {
|
|
30
|
+
process.stderr.write(`[survey] 分片 ${i} 无结果\n`)
|
|
31
|
+
resolve([])
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
resolve(JSON.parse(m[1]))
|
|
36
|
+
} catch {
|
|
37
|
+
resolve([])
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
const rows = (await Promise.all(runs)).flat()
|
|
43
|
+
reportSurvey(rows)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 表格按得分升序:最薄的排最前,那才是要动手的地方。 */
|
|
47
|
+
export function reportSurvey(rows) {
|
|
48
|
+
const scored = rows.filter((r) => typeof r.score === 'number').sort((a, b) => a.score - b.score)
|
|
49
|
+
const skipped = rows.filter((r) => r.skipped)
|
|
50
|
+
console.log('\n模块 变异体 杀掉 得分')
|
|
51
|
+
for (const r of scored) {
|
|
52
|
+
console.log(`${r.rel.padEnd(38)} ${String(r.total).padStart(5)} ${String(r.killed).padStart(5)} ${String(r.score).padStart(6)}%`)
|
|
53
|
+
}
|
|
54
|
+
const avg = scored.length ? scored.reduce((a, r) => a + r.score, 0) / scored.length : 0
|
|
55
|
+
console.log(`\n可测模块 ${scored.length} 个,平均得分 ${avg.toFixed(1)}%;跳过 ${skipped.length} 个`)
|
|
56
|
+
for (const r of skipped) console.log(` 跳过 ${r.rel}:${r.skipped.split(',')[0].slice(0, 50)}`)
|
|
57
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 报点定位(tools/lib/where.mjs,2026-11-30)——工具链共用件,零依赖。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独抽出来:闸门报「哪个文件第几行」时,全仓有 20 处 finding 直接把 `line: 1` 写死。
|
|
5
|
+
* 那不是一个位置,是「文件第一行」——看着像定位,实际把人送到错误的地方。
|
|
6
|
+
* Python 的 traceback 之所以可信,是因为它给的每一行都是真的、可跳转的;
|
|
7
|
+
* **报点一旦有假,人就会学会不看报点**,闸门也就只剩下一个 exit code。
|
|
8
|
+
*
|
|
9
|
+
* 三条纪律:
|
|
10
|
+
* ① 找不到真行号就返回 0,**不拿 1 顶替**;
|
|
11
|
+
* ② 渲染时 line<=0 只给文件名(`path/file.mjs`),不给 `:0`,也不给 `:1`;
|
|
12
|
+
* ③ 行号一律 1-based,与编辑器、编译器、`grep -n` 一致。
|
|
13
|
+
*
|
|
14
|
+
* `line: 0` 有且只有一个意思:**病灶是整份文件**(超长、格式坏了、文件还没建),
|
|
15
|
+
* 不是"某个想不起来的行"。所以它合法地存在,只是不冒充一个具体位置。
|
|
16
|
+
*
|
|
17
|
+
* 反向约束:本模块只做「文件 + 行号 + 那一行原文」,**不做语义判断**。
|
|
18
|
+
* 判据各自知道自己要找什么(模块 id、路径字面量、`<!-- key -->`),
|
|
19
|
+
* 定位是纯机械的事,混进来就会变成第二个判据。
|
|
20
|
+
*/
|
|
21
|
+
import { readFileSync } from 'node:fs'
|
|
22
|
+
import { isAbsolute, join } from 'node:path'
|
|
23
|
+
|
|
24
|
+
/** 原文预览的截断长度:够看清写的是什么,又不至于把终端撑爆。 */
|
|
25
|
+
const SRC_MAX = 120
|
|
26
|
+
|
|
27
|
+
/** 字节偏移 → 1-based 行号。 */
|
|
28
|
+
export function lineAt(text, offset) {
|
|
29
|
+
if (!(offset >= 0)) return 0
|
|
30
|
+
let line = 1
|
|
31
|
+
for (let i = 0; i < offset && i < text.length; i += 1) if (text[i] === '\n') line += 1
|
|
32
|
+
return line
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 第一次出现的位置所在的**行号**;`needle` 可为字符串或正则。
|
|
37
|
+
* 找不到返回 0——这是本模块与旧写法最根本的区别:宁可没有,也不给假值。
|
|
38
|
+
*/
|
|
39
|
+
export function lineOf(text, needle) {
|
|
40
|
+
if (typeof text !== 'string' || !text) return 0
|
|
41
|
+
if (needle instanceof RegExp) {
|
|
42
|
+
const re = needle.global ? needle : new RegExp(needle.source, `${needle.flags}g`)
|
|
43
|
+
const m = re.exec(text)
|
|
44
|
+
return m ? lineAt(text, m.index) : 0
|
|
45
|
+
}
|
|
46
|
+
const k = text.indexOf(needle)
|
|
47
|
+
return k < 0 ? 0 : lineAt(text, k)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 所有出现处的行号(去重、保序)。
|
|
52
|
+
*
|
|
53
|
+
* 为什么需要"第 n 次":同一个路径字面量被两个模块登记时,重叠判据要报**后来那张**,
|
|
54
|
+
* 报第一张等于指回没错的那一行。
|
|
55
|
+
*/
|
|
56
|
+
export function linesOf(text, needle) {
|
|
57
|
+
if (typeof text !== 'string' || !text) return []
|
|
58
|
+
const seen = new Set()
|
|
59
|
+
const out = []
|
|
60
|
+
if (needle instanceof RegExp) {
|
|
61
|
+
const re = needle.global ? needle : new RegExp(needle.source, `${needle.flags}g`)
|
|
62
|
+
let m
|
|
63
|
+
while ((m = re.exec(text))) {
|
|
64
|
+
const line = lineAt(text, m.index)
|
|
65
|
+
if (!seen.has(line)) out.push(line)
|
|
66
|
+
seen.add(line)
|
|
67
|
+
if (!m[0]) re.lastIndex += 1 // 空匹配会原地打转
|
|
68
|
+
}
|
|
69
|
+
return out
|
|
70
|
+
}
|
|
71
|
+
let from = 0
|
|
72
|
+
for (;;) {
|
|
73
|
+
const k = text.indexOf(needle, from)
|
|
74
|
+
if (k < 0) break
|
|
75
|
+
const line = lineAt(text, k)
|
|
76
|
+
if (!seen.has(line)) out.push(line)
|
|
77
|
+
seen.add(line)
|
|
78
|
+
from = k + Math.max(1, needle.length)
|
|
79
|
+
}
|
|
80
|
+
return out
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 取第 n 行的原文(去首尾空白、超长截断);越界或空行返回 ''。 */
|
|
84
|
+
export function sourceLine(text, line) {
|
|
85
|
+
if (typeof text !== 'string' || !(line > 0)) return ''
|
|
86
|
+
const row = text.split('\n')[line - 1]
|
|
87
|
+
if (row == null) return ''
|
|
88
|
+
const t = row.trim()
|
|
89
|
+
return t.length > SRC_MAX ? `${t.slice(0, SRC_MAX)}…` : t
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** `file:line`;行号未知时只给文件名。**永不输出 `:0` 或替身 `:1`。** */
|
|
93
|
+
export function where(file, line) {
|
|
94
|
+
const f = String(file || '').replace(/\\/g, '/')
|
|
95
|
+
return line > 0 ? `${f}:${line}` : f
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 正则转义:版本号、模块 id 里的 `.` `(` 不转义会匹配任意字符,定位就漂到别处去了。
|
|
100
|
+
*
|
|
101
|
+
* 抽出来是因为已经有第二处手写同一串 `replace(/[.*+?^${}()|[\]\\]/g, '\\$&')`——
|
|
102
|
+
* 那种式子抄第二遍时最常漏掉 `]` 或 `\\`,而漏掉之后不报错,只是偶尔定位失灵。
|
|
103
|
+
*/
|
|
104
|
+
export function escapeRe(s) {
|
|
105
|
+
return String(s).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 三段一起取,省得调用方自己 split 一遍。 */
|
|
109
|
+
export function locate(file, text, needle) {
|
|
110
|
+
const line = lineOf(text, needle)
|
|
111
|
+
return { file, line, src: sourceLine(text, line) }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 读文件并取出第 line 行的原文——供 `--where` 显示"出错的那一行"。
|
|
116
|
+
* 读不到就返回 '':报点失败不该让闸门自己崩掉(那是二级故障,不该盖住一级问题)。
|
|
117
|
+
*/
|
|
118
|
+
export function sourceOf(file, line, root) {
|
|
119
|
+
if (!file || !(line > 0)) return ''
|
|
120
|
+
try {
|
|
121
|
+
const abs = isAbsolute(file) ? file : join(root || '.', file)
|
|
122
|
+
return sourceLine(readFileSync(abs, 'utf8'), line)
|
|
123
|
+
} catch {
|
|
124
|
+
return ''
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 单条 finding 的渲染,全仓闸门统一走这里。
|
|
130
|
+
*
|
|
131
|
+
* 默认一行:`file:line\t[rule] detail`——沿用既有格式,改动只在"行号变真"。
|
|
132
|
+
* `withSource` 时追加一行缩进原文,像 traceback 那样把上下文摆在眼前。
|
|
133
|
+
*/
|
|
134
|
+
export function renderFinding(f, { root, withSource = false } = {}) {
|
|
135
|
+
const head = `${where(f.file, f.line)}\t[${f.rule || f.kind}] ${f.detail}`
|
|
136
|
+
if (!withSource) return head
|
|
137
|
+
const src = sourceOf(f.file, f.line, root)
|
|
138
|
+
return src ? `${head}\n │ ${src}` : head
|
|
139
|
+
}
|
package/tools/library-book.mjs
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'
|
|
23
23
|
import { basename, join } from 'node:path'
|
|
24
24
|
import { BOOK_CSS } from './lib/book-style.mjs'
|
|
25
|
+
import { mdToHtml } from './lib/markdown.mjs'
|
|
25
26
|
|
|
26
27
|
const argv = process.argv.slice(2)
|
|
27
28
|
const arg = (k, d) => (argv.includes(k) ? argv[argv.indexOf(k) + 1] : d)
|
|
@@ -30,98 +31,12 @@ const OUT = arg('--out', join(SRC, 'book.html'))
|
|
|
30
31
|
const LABEL = arg('--label', '资料书')
|
|
31
32
|
const UNIT = arg('--unit', '块')
|
|
32
33
|
|
|
33
|
-
// ── markdown
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
function inline(s) {
|
|
41
|
-
return esc(s)
|
|
42
|
-
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
|
|
43
|
-
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function mdToHtml(md) {
|
|
47
|
-
const out = []
|
|
48
|
-
let list = null
|
|
49
|
-
let quote = null
|
|
50
|
-
const flush = () => {
|
|
51
|
-
if (list) {
|
|
52
|
-
out.push(`<${list.tag}>${list.items.map((i) => `<li>${i}</li>`).join('')}</${list.tag}>`)
|
|
53
|
-
list = null
|
|
54
|
-
}
|
|
55
|
-
if (quote) {
|
|
56
|
-
out.push(`<blockquote>${quote.map((i) => `<p>${i}</p>`).join('')}</blockquote>`)
|
|
57
|
-
quote = null
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
for (const raw of String(md).split('\n')) {
|
|
61
|
-
const line = raw.trimEnd()
|
|
62
|
-
if (!line.trim()) {
|
|
63
|
-
flush()
|
|
64
|
-
continue
|
|
65
|
-
}
|
|
66
|
-
const h = /^(#{1,6})\s+(.*)$/.exec(line)
|
|
67
|
-
if (h) {
|
|
68
|
-
flush()
|
|
69
|
-
const lv = Math.min(6, h[1].length + 1)
|
|
70
|
-
out.push(`<h${lv}>${inline(h[2])}</h${lv}>`)
|
|
71
|
-
continue
|
|
72
|
-
}
|
|
73
|
-
// 分隔线:必须在列表之前判,否则 `---` 会被当成空的列表项
|
|
74
|
-
if (/^(-{3,}|\*{3,}|_{3,})$/.test(line.trim())) {
|
|
75
|
-
flush()
|
|
76
|
-
out.push('<hr>')
|
|
77
|
-
continue
|
|
78
|
-
}
|
|
79
|
-
const bq = /^>\s?(.*)$/.exec(line)
|
|
80
|
-
if (bq) {
|
|
81
|
-
if (list) {
|
|
82
|
-
out.push(`<${list.tag}>${list.items.map((i) => `<li>${i}</li>`).join('')}</${list.tag}>`)
|
|
83
|
-
list = null
|
|
84
|
-
}
|
|
85
|
-
if (!quote) quote = []
|
|
86
|
-
quote.push(inline(bq[1]))
|
|
87
|
-
continue
|
|
88
|
-
}
|
|
89
|
-
const ul = /^[-*]\s+(.*)$/.exec(line)
|
|
90
|
-
if (ul) {
|
|
91
|
-
if (!list || list.tag !== 'ul') {
|
|
92
|
-
flush()
|
|
93
|
-
list = { tag: 'ul', items: [] }
|
|
94
|
-
}
|
|
95
|
-
list.items.push(inline(ul[1]))
|
|
96
|
-
continue
|
|
97
|
-
}
|
|
98
|
-
const ol = /^\d+\.\s+(.*)$/.exec(line)
|
|
99
|
-
if (ol) {
|
|
100
|
-
if (!list || list.tag !== 'ol') {
|
|
101
|
-
flush()
|
|
102
|
-
list = { tag: 'ol', items: [] }
|
|
103
|
-
}
|
|
104
|
-
list.items.push(inline(ol[1]))
|
|
105
|
-
continue
|
|
106
|
-
}
|
|
107
|
-
flush()
|
|
108
|
-
// 认笔记自己的体例(三层):整行只有一句粗体的 → 小标题;`→ 接入…` → 动作行;
|
|
109
|
-
// `出处:…` → 出处行。不认这三层的话,每条都摊成四段同样大小的字,读起来一片平。
|
|
110
|
-
const html = inline(line)
|
|
111
|
-
const strongOnly =
|
|
112
|
-
/^<strong>[\s\S]*<\/strong>$/.test(html) && (html.match(/<strong>/g) || []).length === 1
|
|
113
|
-
const cls = strongOnly
|
|
114
|
-
? ' class="h"'
|
|
115
|
-
: line.startsWith('→')
|
|
116
|
-
? ' class="act"'
|
|
117
|
-
: /^出处[::]/.test(line)
|
|
118
|
-
? ' class="ref"'
|
|
119
|
-
: ''
|
|
120
|
-
out.push(`<p${cls}>${html}</p>`)
|
|
121
|
-
}
|
|
122
|
-
flush()
|
|
123
|
-
return out.join('\n')
|
|
124
|
-
}
|
|
34
|
+
// ── markdown ──────────────────────────────────────────────────────────────
|
|
35
|
+
// 2026-11-19:渲染器移到 `lib/markdown.mjs`,与「全仓文档书」(`docs-book.mjs`)共用。
|
|
36
|
+
// 原先这里有一份只认卡片语法的实现;做第二本书时如果再抄一份,两份迟早对同一段
|
|
37
|
+
// markdown 给出不同结果,而且没有任何判据会发现。卡片体例靠 `cardClasses` 选项保留。
|
|
38
|
+
// 顺带补上表格与代码围栏——积木里没有,但共用件必须有。
|
|
39
|
+
export { mdToHtml }
|
|
125
40
|
|
|
126
41
|
/** frontmatter + 正文;没有 frontmatter 就整体当正文。 */
|
|
127
42
|
export function parseBlock(text) {
|
package/tools/library-build.mjs
CHANGED
|
@@ -162,6 +162,11 @@ function main() {
|
|
|
162
162
|
const rows = []; // {id,file,title,sha,src,status}
|
|
163
163
|
const today = new Date().toISOString();
|
|
164
164
|
const normSep = (s) => String(s).replace(/\\/g, "/"); // 幂等配对与平台无关(分隔符归一)
|
|
165
|
+
// 按内容指纹建索引一次(2026-11-28):原实现每块都在 `index.rows.find(...)` 里线性扫一遍,
|
|
166
|
+
// 块数 × 存量行数是 O(n²)。同 sha 取首条——与 `find` 语义一致,且 `index.rows` 在本次
|
|
167
|
+
// 构建过程中不变(新块进的是 `rows`),所以一次性建表与原逐块查找完全等价。
|
|
168
|
+
const bySha = new Map();
|
|
169
|
+
for (const v of index.rows) if (!bySha.has(v.sha)) bySha.set(v.sha, v);
|
|
165
170
|
for (const f of sources) {
|
|
166
171
|
let text;
|
|
167
172
|
try { text = readFileSync(f, "utf8"); } catch { continue; }
|
|
@@ -171,7 +176,7 @@ function main() {
|
|
|
171
176
|
for (const b of pieces) {
|
|
172
177
|
const fp = sha(b.title + "\n" + b.body);
|
|
173
178
|
// 幂等:同内容指纹的积木已存在 → 复用旧 id 与文件(重建不换号;按内容配对,与源路径写法无关)
|
|
174
|
-
const dup =
|
|
179
|
+
const dup = bySha.get(fp);
|
|
175
180
|
if (dup) {
|
|
176
181
|
kept++;
|
|
177
182
|
rows.push({ id: dup.id, file: dup.file, title: b.title, sha: fp, src: rel, status: "保留" });
|
|
@@ -220,10 +225,17 @@ function buildTable(rows) {
|
|
|
220
225
|
"|---|---|---|---|---|---|",
|
|
221
226
|
].join("\n");
|
|
222
227
|
const groups = [];
|
|
228
|
+
// 组名 → 组(2026-11-28):原实现每行 `groups.find(...)` 线性找组,O(行×组)。
|
|
229
|
+
// Map 保留插入序,与原「首次出现即定序」一致;随后的 sort 仍按 themeOrder 定终序。
|
|
230
|
+
const byName = new Map();
|
|
223
231
|
for (const r of rows) {
|
|
224
232
|
const name = themeOf(r.title, r.src);
|
|
225
|
-
let g =
|
|
226
|
-
if (!g)
|
|
233
|
+
let g = byName.get(name);
|
|
234
|
+
if (!g) {
|
|
235
|
+
g = { name, rows: [] };
|
|
236
|
+
byName.set(name, g);
|
|
237
|
+
groups.push(g);
|
|
238
|
+
}
|
|
227
239
|
g.rows.push(r);
|
|
228
240
|
}
|
|
229
241
|
const themeOrder = [...SRC_THEMES.map(([n]) => n), ...THEMES.map(([n]) => n), UNGROUPED];
|
package/tools/lint.mjs
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
* 用法:
|
|
29
29
|
* node packages/core/tools/lint.mjs # 明细
|
|
30
30
|
* node packages/core/tools/lint.mjs --brief # 一行(供 npm run check)
|
|
31
|
+
* node packages/core/tools/lint.mjs --where # 每条问题附上出错那一行原文
|
|
31
32
|
* node packages/core/tools/lint.mjs --json
|
|
32
33
|
* node packages/core/tools/lint.mjs --strict # 超债务上限 exit 1
|
|
33
34
|
* node packages/core/tools/lint.mjs <目录...> # 只扫指定目录
|
|
@@ -42,24 +43,22 @@
|
|
|
42
43
|
*/
|
|
43
44
|
|
|
44
45
|
import { readFileSync } from 'node:fs'
|
|
45
|
-
import {
|
|
46
|
-
import { fileURLToPath } from 'node:url'
|
|
46
|
+
import { relative, resolve } from 'node:path'
|
|
47
47
|
// 去字面量与注释:与 smells.mjs 共用同一实现(2026-10-27 抽到 tools/lib/)。
|
|
48
48
|
// 各写一份必然分叉——smells 那份就漏了正则字面量,把 398 行的函数抹成 0。
|
|
49
49
|
import { stripLiterals } from './lib/source-text.mjs'
|
|
50
50
|
// 目录遍历复用 lib 里那一份:带 SKIP_DIRS 的版本曾在 lint / smells 各抄一遍(2026-11-17 收成参数)。
|
|
51
51
|
import { walk } from './lib/import-graph.mjs'
|
|
52
|
+
import { scanIdioms, IDIOMS } from './lib/idioms.mjs'
|
|
53
|
+
import { renderFinding } from './lib/where.mjs'
|
|
54
|
+
import { has, positionals, repoRoot } from './lib/cli.mjs'
|
|
52
55
|
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const BRIEF = argv.includes('--brief')
|
|
60
|
-
const AS_JSON = argv.includes('--json')
|
|
61
|
-
const STRICT = argv.includes('--strict')
|
|
62
|
-
const dirArgs = argv.filter((a) => !a.startsWith('--'))
|
|
56
|
+
const REPO = repoRoot(import.meta.url)
|
|
57
|
+
const BRIEF = has('--brief')
|
|
58
|
+
const AS_JSON = has('--json')
|
|
59
|
+
const WHERE = has('--where')
|
|
60
|
+
const STRICT = has('--strict')
|
|
61
|
+
const dirArgs = positionals()
|
|
63
62
|
|
|
64
63
|
const DEFAULT_ROOTS = ['packages/core/src', 'packages/core/tools', 'packages/core/tests', 'packages/core/hooks', 'packages/extended/src']
|
|
65
64
|
const roots = (dirArgs.length ? dirArgs : DEFAULT_ROOTS).map((d) => resolve(REPO, d))
|
|
@@ -71,6 +70,9 @@ const roots = (dirArgs.length ? dirArgs : DEFAULT_ROOTS).map((d) => resolve(REPO
|
|
|
71
70
|
const BUDGET = 0
|
|
72
71
|
const GATED = /^packages\/(core\/(src|tools|tests)|extended\/src)\//
|
|
73
72
|
|
|
73
|
+
/** brief 超限时逐条点名的上限。 */
|
|
74
|
+
const BRIEF_SHOW = 8
|
|
75
|
+
|
|
74
76
|
const SKIP_DIRS = new Set(['node_modules', '.git', '.stryker-tmp', '.mutate-tmp', 'reports', '.ai'])
|
|
75
77
|
|
|
76
78
|
/**
|
|
@@ -137,6 +139,9 @@ const RULES = {
|
|
|
137
139
|
var: '使用 var(应 let/const)',
|
|
138
140
|
'loose-equal': '使用 == / !=(两侧均非 null/undefined)',
|
|
139
141
|
'console-in-src': 'console.log 留在 src/(污染输出)',
|
|
142
|
+
...Object.fromEntries(IDIOMS.map((r) => [r.id, r.why])),
|
|
143
|
+
'filter-first': 'filter(...)[0] 应换 find(...)(少一次全表扫描 + 少一个数组)',
|
|
144
|
+
'filter-length': 'filter(...).length 应换 some/every(命中即停)',
|
|
140
145
|
}
|
|
141
146
|
|
|
142
147
|
const findings = []
|
|
@@ -233,6 +238,7 @@ for (const file of files) {
|
|
|
233
238
|
checkVar(file, plain)
|
|
234
239
|
checkLooseEqual(file, plain)
|
|
235
240
|
checkConsole(file, plain)
|
|
241
|
+
for (const hit of scanIdioms(plain, src)) report(file, hit.line, hit.rule, hit.detail)
|
|
236
242
|
}
|
|
237
243
|
|
|
238
244
|
const byRule = {}
|
|
@@ -250,11 +256,16 @@ if (AS_JSON) {
|
|
|
250
256
|
.map(([r, n]) => `${r} ${n}`)
|
|
251
257
|
const gate = gated.length > BUDGET ? `活跃层 ${gated.length} 条 > 上限 ${BUDGET} ❌` : `活跃层 ${gated.length}/${BUDGET} ✅`
|
|
252
258
|
console.log(`房规检查:${files.length} 文件,问题 ${findings.length} 条${parts.length ? `(${parts.join(' / ')})` : ''};${gate}${frozen ? `,封存层 ${frozen} 条不计` : ''}`)
|
|
259
|
+
// 超限就把活跃层 offenders 就地列出来:CI 上看到"1 条 > 上限 0"却不知道是哪一行,等于又跑一趟。
|
|
260
|
+
if (gated.length > BUDGET) {
|
|
261
|
+
for (const f of gated.slice(0, BRIEF_SHOW)) console.log(` ${renderFinding(f, { root: REPO, withSource: WHERE })}`)
|
|
262
|
+
if (gated.length > BRIEF_SHOW) console.log(` …另 ${gated.length - BRIEF_SHOW} 条,跑 npm run lint 看全量`)
|
|
263
|
+
}
|
|
253
264
|
} else {
|
|
254
265
|
console.log(`房规检查:${files.length} 文件,问题 ${findings.length} 条\n`)
|
|
255
266
|
if (!findings.length) console.log('无问题。')
|
|
256
267
|
for (const f of findings.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line)) {
|
|
257
|
-
console.log(
|
|
268
|
+
console.log(renderFinding(f, { root: REPO, withSource: WHERE }))
|
|
258
269
|
}
|
|
259
270
|
console.log('\n不报的三类(各有理由):curly 房规 / `== null` 惯用法 / 空 catch 三级兜底。')
|
|
260
271
|
console.log(`闸门口径:活跃层 ${gated.length} 条 / 上限 ${BUDGET};封存层 ${frozen} 条(hooks/)只报不计。`)
|