unbounded-spread through tuple aliases, code-range-compare skips tables of measures, prototype patches through imported helpers, stable-shape once per literal #161

Merged
sionzee merged 6 commits from spread-range-patch into main 2026-11-24 14:08:14 +01:00
Owner

Four small items from an adopter's feedback on 0.5.1. Each has its own commit, fixtures, docs and CHANGELOG line.

1. unbounded-spread: a tuple type named by an alias

Was wrong: a tuple without a rest element has a fixed length, but the rule only recognised one written in place.

type V = readonly [x: number, y: number, z: number];
export function g(xs: number[], v: V): number { xs.push(...v); return Math.hypot(...v); } // both reported

Changed: known_length is now a three-way Length (known, unknown, or known if certain imported types are fixed tuples). It follows type aliases of the same file, Readonly<...>, unions of tuples (ignoring | undefined), and labelled and optional elements. It also reads a ?? b, c ? a : b and v! of such lists. Imported aliases go to the whole-program pass: each file records its tuple_aliases, the finding becomes a Site with lists, and Run::project_fixed_tuple follows re-exports and aliases of aliases across files.
Still reported: [number, ...number[]], type Wrapped<T> = T used as Wrapped<number[]>, a union with an array, and [...v, ...rest]. Fixtures: unbounded_spread/tuples.ts, tuple_types.ts, tuple_reexport.ts.

2. code-range-compare: tables of tuning numbers (sound part only)

Was wrong: const SHAKE = Object.freeze({ px: 7, ms: 650, reach: 1.5 }); elapsed > SHAKE.ms was reported as picking members by their codes.
Changed: codes are whole numbers (places in a list). A table with a value that isn't a whole number holds measures, so the rule skips it. Docs and README now say "code object of whole numbers".
Still reported: any table of whole numbers, including hand-written code tables with gaps (fixtures Step, Gapped in closed_set_guards/main.ts). Tuning tables that hold only whole numbers are also still reported. That includes the adopter's own probe Object.freeze({ ms: 300, maxRange: 12 }): I found no sound way to tell those from codes. Options are listed below.

Adopter tree, before → after: 139 → 114. All 25 that disappear are tuning tables (camera shake, procedural atlas metrics, smoke, grass LOD, tree shake, snow prints, object contact, a house-art layout table, fire light). Every one has a fraction among its values. No code table disappears: PHASE ×54, LifeStage ×45, PanicStage, Weather, SimError, PileState, GriefTie, GriefStage, FieldStage and BuildingKind are all still reported. Two tuning tables of whole numbers are still reported (4 findings).

3. no-foreign-prototype-patch: helper imported from another file

Was wrong: patchMethod(HTMLElement.prototype, "glow", ...) was reported only when patchMethod was declared in the same file. The docs said so.
Changed: each file records what its top-level functions do with their parameters (lifetime::patch_helpers): which ones they patch, and which they hand to another function of the file or an imported one. A call that hands a foreign prototype to an imported function (or to a local one that hands it on) becomes a PatchCall. The whole-program pass resolves it (Run::patching_params) by name, as a namespace member, as the default export, through re-exports, and through chains across files. It also follows const copies, plain and destructured. A no-mutable-global finding on the same call is dropped, as the file's own pass already does. Docs sentence updated (rule page, guide state.md, README).
Still reported / still silent: a helper that only reads its parameter, an argument the helper doesn't patch, and the module's own class (no-mutable-global's) — fixture lifetime/imported.ts with patchers*.ts.

Adopter tree: 18 → 25. The 7 new findings are all real: pixi prototypes patched through an imported pixiPatch helper.

4. stable-shape: one finding per literal

Was wrong: a literal with three conditional spreads gave the same finding three times, once at each spread.
Changed: one finding per literal, at its first conditional spread. Where the message is the spread's own, it adds how many spreads the literal has. The fixture harness compares sets, so a test in tests/messages.rs checks the count. On the adopter tree no other rule repeats a finding with the same rule and span. The only same-line repeats are separate calls on one line, which is expected.

Tests

  • cargo nextest run --workspace (fast profile): 413 passed.
  • npm run test:rewrites (full mode): passes after a bless. Every moved count was compared against main's full-mode report. All differences are on the new fixture lines, or on lines that moved down by one after an added import. One new line, text no-foreign-prototype-patch namespace-import 4, gets a reason: the message names the helper as it is imported by name. Note: main (2cd63b1e) already fails full mode on text aliased-mut call (14 → 16) and on 3 of the new missing-mut hoist-const sites, both from mut_two_names (#150). The bless includes those.
  • work ceilings hold: the new summaries allocate only for what they keep.
  • npm run test:soundness: 16 of 110 classes escape, exactly escaping.txt.
  • npm run test:docs: builds.

Open question (item 2)

What should happen to code-like tables of whole numbers that hold thresholds ({ ms: 300, maxRange: 12 }, { x: 28, up: 48, down: 8 })? Options:

  • a. Treat a table whose values aren't consecutive (or close to it) as non-codes, with codesOf tables always codes. This drops real code tables with gaps, such as save formats with removed members.
  • b. Treat duplicate values as non-codes. This misses code tables with alias names.
  • c. Leave the rule as it is and point to /** @ordered */ or a const per threshold, which the docs now do.

🤖 Generated with Claude Code

Four small items from an adopter's feedback on 0.5.1. Each has its own commit, fixtures, docs and CHANGELOG line. ## 1. `unbounded-spread`: a tuple type named by an alias **Was wrong:** a tuple without a rest element has a fixed length, but the rule only recognised one written in place. ```ts type V = readonly [x: number, y: number, z: number]; export function g(xs: number[], v: V): number { xs.push(...v); return Math.hypot(...v); } // both reported ``` **Changed:** `known_length` is now a three-way `Length` (known, unknown, or known if certain imported types are fixed tuples). It follows type aliases of the same file, `Readonly<...>`, unions of tuples (ignoring `| undefined`), and labelled and optional elements. It also reads `a ?? b`, `c ? a : b` and `v!` of such lists. Imported aliases go to the whole-program pass: each file records its `tuple_aliases`, the finding becomes a `Site` with `lists`, and `Run::project_fixed_tuple` follows re-exports and aliases of aliases across files. **Still reported:** `[number, ...number[]]`, `type Wrapped<T> = T` used as `Wrapped<number[]>`, a union with an array, and `[...v, ...rest]`. Fixtures: `unbounded_spread/tuples.ts`, `tuple_types.ts`, `tuple_reexport.ts`. ## 2. `code-range-compare`: tables of tuning numbers (sound part only) **Was wrong:** `const SHAKE = Object.freeze({ px: 7, ms: 650, reach: 1.5 }); elapsed > SHAKE.ms` was reported as picking members by their codes. **Changed:** codes are whole numbers (places in a list). A table with a value that isn't a whole number holds measures, so the rule skips it. Docs and README now say "code object of whole numbers". **Still reported:** any table of whole numbers, including hand-written code tables with gaps (fixtures `Step`, `Gapped` in `closed_set_guards/main.ts`). Tuning tables that hold only whole numbers are also still reported. That includes the adopter's own probe `Object.freeze({ ms: 300, maxRange: 12 })`: I found no sound way to tell those from codes. Options are listed below. Adopter tree, before → after: 139 → 114. All 25 that disappear are tuning tables (camera shake, procedural atlas metrics, smoke, grass LOD, tree shake, snow prints, object contact, a house-art layout table, fire light). Every one has a fraction among its values. No code table disappears: PHASE ×54, LifeStage ×45, PanicStage, Weather, SimError, PileState, GriefTie, GriefStage, FieldStage and BuildingKind are all still reported. Two tuning tables of whole numbers are still reported (4 findings). ## 3. `no-foreign-prototype-patch`: helper imported from another file **Was wrong:** `patchMethod(HTMLElement.prototype, "glow", ...)` was reported only when `patchMethod` was declared in the same file. The docs said so. **Changed:** each file records what its top-level functions do with their parameters (`lifetime::patch_helpers`): which ones they patch, and which they hand to another function of the file or an imported one. A call that hands a foreign prototype to an imported function (or to a local one that hands it on) becomes a `PatchCall`. The whole-program pass resolves it (`Run::patching_params`) by name, as a namespace member, as the default export, through re-exports, and through chains across files. It also follows `const` copies, plain and destructured. A `no-mutable-global` finding on the same call is dropped, as the file's own pass already does. Docs sentence updated (rule page, guide `state.md`, README). **Still reported / still silent:** a helper that only reads its parameter, an argument the helper doesn't patch, and the module's own class (`no-mutable-global`'s) — fixture `lifetime/imported.ts` with `patchers*.ts`. Adopter tree: 18 → 25. The 7 new findings are all real: pixi prototypes patched through an imported `pixiPatch` helper. ## 4. `stable-shape`: one finding per literal **Was wrong:** a literal with three conditional spreads gave the same finding three times, once at each spread. **Changed:** one finding per literal, at its first conditional spread. Where the message is the spread's own, it adds how many spreads the literal has. The fixture harness compares sets, so a test in `tests/messages.rs` checks the count. On the adopter tree no other rule repeats a finding with the same rule and span. The only same-line repeats are separate calls on one line, which is expected. ## Tests - `cargo nextest run --workspace` (fast profile): 413 passed. - `npm run test:rewrites` (full mode): passes after a bless. Every moved count was compared against main's full-mode report. All differences are on the new fixture lines, or on lines that moved down by one after an added import. One new line, `text no-foreign-prototype-patch namespace-import 4`, gets a reason: the message names the helper as it is imported by name. **Note:** main (2cd63b1e) already fails full mode on `text aliased-mut call` (14 → 16) and on 3 of the `new missing-mut hoist-const` sites, both from `mut_two_names` (#150). The bless includes those. - `work` ceilings hold: the new summaries allocate only for what they keep. - `npm run test:soundness`: 16 of 110 classes escape, exactly `escaping.txt`. - `npm run test:docs`: builds. ## Open question (item 2) What should happen to code-like tables of whole numbers that hold thresholds (`{ ms: 300, maxRange: 12 }`, `{ x: 28, up: 48, down: 8 }`)? Options: - **a.** Treat a table whose values aren't consecutive (or close to it) as non-codes, with `codesOf` tables always codes. This drops real code tables with gaps, such as save formats with removed members. - **b.** Treat duplicate values as non-codes. This misses code tables with alias names. - **c.** Leave the rule as it is and point to `/** @ordered */` or a `const` per threshold, which the docs now do. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A tuple type without a rest element has a fixed length: follow type
aliases of the same file and imported ones (the whole-program pass,
through Site::lists and the file's tuple_aliases), Readonly<...>, unions
of tuples, and ?? / ?: / ! of such lists. A rest element and an alias of
a type parameter stay reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codes are whole numbers (places in a list): a frozen or as-const table
with 0.35 or 1.5 among its values holds tuning numbers, and a compare
with one is a threshold. Tables of whole numbers stay reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each file now says what its top-level functions do with their
parameters (patch_helpers: patched, or handed on to a function of the
file or an imported one), and the calls handing a foreign prototype to
an imported function become PatchCalls the whole-program pass resolves
(by name, namespace member, default export, re-exports, chains through
other files). An overlapping no-mutable-global finding is dropped, as in
the file's own pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shapes come from all the spreads together: report the literal once,
at its first conditional spread, instead of the same finding per spread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fewer allocations for the new summaries; follow const copies of imported helpers
All checks were successful
Benchmarks / bench (pull_request) Successful in 6m23s
Tests / test (pull_request) Successful in 31m30s
01d755c3f2
The tuple-alias and patch-helper summaries allocate only for what they
keep (the work ceilings hold); a strict file's patch helpers come from
its lifetime pass instead of a second walk. no-foreign-prototype-patch
also reads const copies of a namespace's helper (plain and destructured).
misses.txt: the new fixture lines' spellings (full mode).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge main into spread-range-patch
Some checks failed
Tests / test (pull_request) Has been cancelled
Benchmarks / bench (pull_request) Has been cancelled
e6897f059b
Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee deleted branch spread-range-patch 2026-11-24 14:08:14 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!161
No description provided.