Repository navigation
Commit 1aa9c57
refactor(lint): split rule-explanations.ts into one file per rule family (#38808)
<!-- claude-projects-attribution: {"github_login":"huangyiirene"} -->
_Requested by **Irene** · [project
thread](https://claude.ai/code/project/chan_01TJXtQ1tVD26ecLDZxFS67x?thread=cmsg_01TJXtQ1tVD26ecLDZxFS67xAvpYyRcBsXXYFFKdX4WDo1)_
Fixes #38666
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户无感:命令行解释规则时打印的文字一字不变,只是存放这些解释的源文件从一个七千多行的大文件拆成按规则族分开的小文件。
- 为什么做:这是全仓最多人同时修改的文件,属于您批准的大文件拆分计划的第三张卡,拆开后各张加规则的卡不再互相冲突。
- 出错会怎样:最坏是某条规则的解释文字变了或丢了;已逐条比对全部规则的输出完全相同,出问题可直接整体撤回本合并。
- 要你做什么:变更超过三千行,并改了两份设计决策文档里的文件路径指针,需要您批准合并。
## What changes
- `packages/lint/src/rule-explanations.ts` was one 7,680-line table. It
is now the index: the module docblock and the `RuleExplanation`
interface (both verbatim), the family imports, `RULE_EXPLANATIONS` (the
same object literal, so the same keys in the same insertion order) and
`explainRule` (verbatim). A comment above the imports says a new entry
goes into its family's file and a new family gets its own file.
- `packages/lint/src/rule-explanations/` holds one file per family: one
per `// ──` section header of the old file (65), plus
`field-consumers.ts` for `field-no-consumers`, which sat above the first
header. Each entry moved verbatim; the only edit on a moved line is
`export` in front of its `const`.
- `rule-explanations/shared.ts` holds the three paragraphs more than one
family references (`UNPROVISIONED_ANCHOR_CAUSE` and
`UNPROVISIONED_ANCHOR_REMEDY`, used by 7 families, and
`AGGREGATE_PAIR_ROWS`, used by 2), moved with their docblocks.
- Two entries moved to where their header says they belong:
`security-owd-unset` (above the first header) into
`security-posture.ts`, the family of the rule file that produces it, and
`seed-value-outside-state-machine` (inside the assignment-rules section)
under its own header, which was empty, in `seed-state-machine.ts`.
- `rule-explanations.test.ts`: only the case "the module imports
nothing" changes, to the split's equivalent invariant (claim amendment
7295823844): the index imports only `./rule-explanations/*.js` as
values; every family file reached from it imports only siblings, plus
`RuleExplanation` from the index as `import type`; no file re-exports
with export-from. Every other lint test is byte-unchanged.
- `docs/adr/0055-…md` and `docs/adr/0141-…md`: one symbol anchor each
re-pointed from `rule-explanations.ts#NAME` to the family file that now
declares `NAME`, path only, sentence unchanged (claim amendment
7296411486). `check:adr-symbol-anchors` reds without it.
- A `patch` changeset for `@objectstack/lint`: the bundled
`rule-explanations` and `index` entries change bytes (module order,
source-path comments), with no behaviour or declaration change.
- No file in the new set is over 2,000 lines: the largest is
`record-writes.ts` at 623, and the index is 745. There is no
`facade-delegation-registry.json` row: this is a table, not a facade.
## Tests
<details><summary><code>os explain</code> for every rule id: 292 of 292
byte-identical</summary>
The CLI was built once at the base (`3000662c`), then `os explain ID`
ran for every key of `RULE_EXPLANATIONS` (292 ids, stdout, stderr and
the exit code captured per id) against the lint `dist` built from the
base and again against the lint `dist` built from this branch. The CLI
reads the table only through `@objectstack/lint/rule-explanations`, so
the lint build is the only variable.
```bash
# from packages/cli, ids.txt = Object.keys(RULE_EXPLANATIONS), one per line
cat ids.txt | xargs -P 6 -I{} sh -c 'f=$(printf %s "$1" | sed "s#/#__#g"); node bin/run.js explain "$1" > "$2/$f.out" 2>&1; echo "exit=$?" >> "$2/$f.out"' _ {} OUTDIR
diff -r before/explain after/explain && echo "ALL 292 IDENTICAL"
```
Result: `ALL 292 IDENTICAL`; every output exits 0 and opens with its
`Rule:` header; the per-file sha256 manifest hashes to
`c0705a6eac1357072ee4593b166a969264aeab25c0450ef5e2cdea8eb97a0350` on
both sides. `JSON.stringify(RULE_EXPLANATIONS)` from the ESM and the CJS
entry hashes to
`d031c3c5771bb2e806719a5fe5c1fd291cd643d24c979248999d9baefefa0d29`
before and after (key order included).
</details>
<details><summary>Public declaration: all 8 <code>.d.ts</code> /
<code>.d.cts</code> files byte-identical</summary>
`cmp` of
`packages/lint/dist/{index,runtime,runtime-HASH,rule-explanations}.d.{ts,cts}`
before and after: `IDENTICAL` for all eight. (A first cut put the
imports above the interface, which dropped the module docblock from
`rule-explanations.d.ts`; the imports now follow the interface, so the
docblock stays its leading comment.)
</details>
<details><summary>The published entry still imports nothing</summary>
A count of import statements and `require(` calls in
`dist/rule-explanations.js` and `dist/rule-explanations.cjs` reads `0`
and `0`: with `splitting: false` the bundle inlines the family files.
The bundles grow by about 3 KB (source-path comments).
</details>
<details><summary>Lint suite, typecheck, build</summary>
At `939ffdd2` (the last source change; later commits are the changeset
and the two ADR anchors):
- `pnpm --filter @objectstack/lint build`: exit 0, `check-dts-emitted:
6/6`.
- `pnpm --filter @objectstack/lint typecheck` (tsc plus
`check:test-typecheck`): exit 0.
- `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2`:
`Test Files 255 passed (255)`, `Tests 10185 passed (10185)`.
</details>
<details><summary>The rewritten test can fail (three mutations, each
restored to HEAD)</summary>
Through `scripts/ablation-replace.mjs`, running `vitest run
src/rule-explanations.test.ts -t imports`:
1. a family file (`view-refs.ts`) gains a value import of
`../validate-field-consumers.js`: red, "view-refs.js imports outside its
family directory".
2. that file imports the index as a value (`import { type
RuleExplanation }`): red, "view-refs.js imports the index as a value".
3. the index gains a bare side-effect import of
`./validate-field-consumers.js`: red, "expected 66 to be 67" (an import
the reader cannot parse fails the count).
Each run ended "restored: blob == HEAD, `git diff HEAD` is empty".
</details>
## Acceptance notes
- The claim's surface was amended twice by the dispatching seat: the one
test case (amendment 7295823844) and the two ADR anchor lines (amendment
7296411486).
- `packages/lint/tsup.config.ts` and `packages/cli/src/utils/format.ts`
still say in a comment that the entry "imports nothing". That stays true
of the published bundle, so they are untouched.
- Volatile counts above (292 ids, 65 headers, file sizes) are readings
of this head for review, not text in the tree.
## Verification
Read first, by risk: `packages/lint/src/rule-explanations.ts` (the
index: the imports and the unchanged `RULE_EXPLANATIONS` literal),
`packages/lint/src/rule-explanations.test.ts` (the one rewritten case),
`packages/lint/src/rule-explanations/shared.ts`.
Two-minute check: `pnpm --filter @objectstack/lint build && node
packages/cli/bin/run.js explain field-no-consumers` prints the same text
as on `main`.
<details><summary>Derived gates: 77 derived, 75 run green, 2 NOT
MEASURED (local reconciliation)</summary>
`node scripts/pm/dispatch-gates.mjs --commands` on this branch derived
77 commands (71 at `be77abe2`, plus 6 the ADR edit added at `22efc3478`;
`be77abe2` and `22efc3478` differ only by the two ADR anchor lines).
`--ran` reconciliation: "77 derived, 75 run, 2 NOT-MEASURED, 0 UNRUN".
Two reds were seen and cleared: `check:adr-symbol-anchors` (the two ADR
anchors, fixed in `22efc3478`, re-run green on that head) and
`check-plugin-teardown-shape.mjs --self-test` (its pinned fixture commit
was missing from the shallow clone; green after fetching it). The two
NOT MEASURED gates need every package's `dist`, which a whole-repo build
would give; CI runs them.
```text
node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-adr-links.mjs :: exit 0
node scripts/check-adr-links.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-adoption.mjs :: exit 0
node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-dts-emitted.mjs --self-test :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-issue-citations.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0
node scripts/check-temporal-live-filter.mjs :: exit 0
node scripts/check-temporal-live-filter.mjs --self-test :: exit 0
node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/docs-audit/check-affected-docs.mjs :: exit 0
node scripts/docs-audit/check-drift-comment.mjs :: exit 0
node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm check:adr-anchors :: exit 0
pnpm check:adr-index :: exit 0
pnpm check:adr-symbol-anchors :: exit 0
pnpm check:authz-resolver :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:ci-filter-parity :: exit 0
pnpm check:cli-command-ids :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:doc-authoring :: exit 0
pnpm check:docs-transcript-drift :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:dts-closure :: exit 0
NOT-MEASURED pnpm check:dual-build-cjs-loads :: PREREQUISITE NOT MET (exit 3) — reads every package dist; a whole-repo build is outside the foreground budget; CI Lint & Repo Gates runs it after Build
pnpm check:engine-double-contract :: exit 0
pnpm check:error-status-conformance :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:issue-citations :: exit 0
pnpm check:keyed-text-bounds :: exit 0
pnpm check:lean-entry-closure :: exit 0
pnpm check:logger-receiver-detach :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:object-def-param-keys :: exit 0
pnpm check:objectql-double-limit :: exit 0
pnpm check:optional-error-sink :: exit 0
pnpm check:org-identifier :: exit 0
pnpm check:page-declaration-shape :: exit 0
pnpm check:platform-object-tenancy-census :: exit 0
pnpm check:pm-governed-merges :: exit 0
pnpm check:pm-prior-rulings :: exit 0
pnpm check:published-files :: exit 0
NOT-MEASURED pnpm check:published-readme-exports :: PREREQUISITE NOT MET (exit 3) — reads every package dist; a whole-repo build is outside the foreground budget; CI Lint & Repo Gates runs it after Build
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:settings-bind-window :: exit 0
pnpm check:slot-lookup :: exit 0
pnpm check:sourcemap-no-sources-content :: exit 0
pnpm check:system-context-census :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:vouch-for-reference-callers :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
```
</details>
Every family CI runs is read from this PR's check runs, not re-run here.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01J8VVAoVoLCk7JiHvytWEqY)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 7625001 commit 1aa9c57
72 files changed
Lines changed: 7971 additions & 7328 deletions
File tree
- .changeset
- docs/adr
- packages/lint/src
- rule-explanations
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
146 | 177 | | |
147 | 178 | | |
0 commit comments