Migration skill census: one checker run, casts and fetch from code, scripts pass the idiomatic rules #157

Merged
sionzee merged 2 commits from census-skill-upgrade into main 2026-11-24 14:08:02 +01:00
Owner

Feedback from an adopter on the migration skill (skills/safe-ts-migrate) and its census script.

What was wrong (reproduced on main)

  1. The census ran the checker in parts. It passed every scanned file as an entry, split into ~24k-character command lines, so whole-program rules only saw one part at a time. On an adopter's tree (apps packages scripts), the census reported no-optional-field 1146 times where safe-ts check apps packages scripts --idiomatic reports 821: a type that a parseJson<T> in another part reads is exempt from that rule. It also reported unused-code 13 times where check reports 83.
  2. The scripts failed the adopter's lint setup, but only with "idiomatic": true in package.json: no-swallowed-error on the git ls-files fallback (catch { return undefined; }). The other findings in the feedback (unhandled-failure, no-object-dictionary, require-array-sort-compare) were already fixed by #90. The repo test linted without the idiomatic rules, so it missed this one.
  3. as-cast still counted non-casts. #90 had already fixed multi-line import/export renames. The remaining false positives were English inside strings and templates (test('… is rejected as DUPLICATE_SEQ'), a SQL migration template with -- … as JSON) and mapped-type key remaps whose [ sits on the line above:
    readonly [
      I in keyof T as I extends `${number}` ? … : never
    ]: …
    
  4. raw-fetch counted a feature pack's safe fetch imported by name (import { fetch } from "@evobug_com/safe-ts-feature-browser/fetch"), and a method named fetch (async fetch(input, init) {).
  5. module-let in test files: doesn't reproduce on main. #90 already skips test files, using the checker's definition of a test file. no-mutable-global still reports those lets. The one hit left on the adopter's tree is a real module let in a script.

What changed

  • census.mjs runs safe-ts check <the dirs/files it was given> --json --idiomatic once (. by default; --entry is still honoured). There is no more chunking or position-based deduplication, so two casts at one position ({} as never as T) count twice, as check reports them. The report and the JSON show the command's entries ("entries": ["apps", "packages", "scripts"]).
  • The cast patterns test the code only. A small scanner blanks string, template and regex-literal text, comments, a .vue file's markup outside <script>, and the as of a key remap, including across lines. A cast inside ${...} still counts.
  • raw-fetch reads the file's named imports. If a file imports fetch (or x as fetch), its bare fetch( calls aren't the global. { fetch as safeFetch } leaves the bare name global. Method definitions are skipped. globalThis.fetch( and window.fetch( now count. A parameter or local variable named fetch isn't followed (documented): such a call still counts.
  • gitFiles uses spawnSync and checks the exit status instead of try/catch.
  • Upgrade steps (SKILL.md, plus the copy in docs/guide/migration-skill.md, which adoption.md's "Upgrading and bulk fixes" links to): bump every package together (with the npm lockfile / ERESOLVE note), take the census, run safe-ts migrate mut <dirs> --write when moving to 0.5+, run safe-ts fix <rule> <dirs> (prints the diff; --write applies), audit ''/0 comparisons, reinstall the skill with --force. I checked each command against safe-ts --help. The docs use <version> so the examples don't go stale.

What is still reported

  • Real casts, including one inside a template's ${...}, and as unknown as / as never / as any.
  • The global fetch through any spelling the census can see, an aliased global (const fetch = globalThis.fetch), axios and XMLHttpRequest.
  • Fixture src/sim.ts covers string/template English (not counted), a multi-line key remap (not counted) and a template cast (counted). The new src/requests.ts covers an imported pack fetch (not counted), a method (not counted) and globalThis.fetch (counted).

Tests

  • packages/safe-ts-skill/test/skill.test.ts: 11 pass.
    • New: the census's checker counts equal one safe-ts check src --idiomatic --json run, per rule and file.
    • The lint test now enables idiomatic and also runs safe-ts check --idiomatic on census.mjs, safe-ts.mjs and install.mjs (expects []). Put back on main's census, it reports no-swallowed-error.
  • cargo nextest run -p safe_ts_core --test docs: 4 pass. npm run test:docs: builds.
  • With the adopter's own lint config (type-aware, every rule an error, .claude/** un-ignored), vp lint .claude is clean.
  • Rules weren't touched, so I didn't run the rewrites/soundness suites.

Adopter tree, before → after

main this branch safe-ts check apps packages scripts --idiomatic
no-optional-field 1146 821 821
unused-code 13 83 83
all rules, per rule and file differ identical (1187 rule×file rows) —
as-cast 11 1 (the real cast)
raw-fetch 14 2 (an aliased global in a test helper; a call through a parameter named fetch)
module-let 1 1

On this repo's own packages examples docs, every hit the new census drops is a false positive: test names, a string holding an import line, fixture cases, and a pack fetch import.

🤖 Generated with Claude Code

Feedback from an adopter on the migration skill (`skills/safe-ts-migrate`) and its census script. ## What was wrong (reproduced on main) 1. **The census ran the checker in parts.** It passed every scanned file as an entry, split into ~24k-character command lines, so whole-program rules only saw one part at a time. On an adopter's tree (`apps packages scripts`), the census reported `no-optional-field` 1146 times where `safe-ts check apps packages scripts --idiomatic` reports 821: a type that a `parseJson<T>` in another part reads is exempt from that rule. It also reported `unused-code` 13 times where `check` reports 83. 2. **The scripts failed the adopter's lint setup**, but only with `"idiomatic": true` in package.json: `no-swallowed-error` on the `git ls-files` fallback (`catch { return undefined; }`). The other findings in the feedback (`unhandled-failure`, `no-object-dictionary`, `require-array-sort-compare`) were already fixed by #90. The repo test linted without the idiomatic rules, so it missed this one. 3. **`as-cast` still counted non-casts.** #90 had already fixed multi-line import/export renames. The remaining false positives were English inside strings and templates (`test('… is rejected as DUPLICATE_SEQ')`, a SQL migration template with `-- … as JSON`) and mapped-type key remaps whose `[` sits on the line above: ```ts readonly [ I in keyof T as I extends `${number}` ? … : never ]: … ``` 4. **`raw-fetch` counted a feature pack's safe `fetch` imported by name** (`import { fetch } from "@evobug_com/safe-ts-feature-browser/fetch"`), and a method named `fetch` (`async fetch(input, init) {`). 5. **`module-let` in test files:** doesn't reproduce on main. #90 already skips test files, using the checker's definition of a test file. `no-mutable-global` still reports those `let`s. The one hit left on the adopter's tree is a real module `let` in a script. ## What changed - `census.mjs` runs `safe-ts check <the dirs/files it was given> --json --idiomatic` once (`.` by default; `--entry` is still honoured). There is no more chunking or position-based deduplication, so two casts at one position (`{} as never as T`) count twice, as `check` reports them. The report and the JSON show the command's entries (`"entries": ["apps", "packages", "scripts"]`). - The cast patterns test the code only. A small scanner blanks string, template and regex-literal text, comments, a `.vue` file's markup outside `<script>`, and the `as` of a key remap, including across lines. A cast inside `${...}` still counts. - `raw-fetch` reads the file's named imports. If a file imports `fetch` (or `x as fetch`), its bare `fetch(` calls aren't the global. `{ fetch as safeFetch }` leaves the bare name global. Method definitions are skipped. `globalThis.fetch(` and `window.fetch(` now count. A parameter or local variable named `fetch` isn't followed (documented): such a call still counts. - `gitFiles` uses `spawnSync` and checks the exit status instead of try/catch. - Upgrade steps (SKILL.md, plus the copy in `docs/guide/migration-skill.md`, which `adoption.md`'s "Upgrading and bulk fixes" links to): bump every package together (with the npm lockfile / `ERESOLVE` note), take the census, run `safe-ts migrate mut <dirs> --write` when moving to 0.5+, run `safe-ts fix <rule> <dirs>` (prints the diff; `--write` applies), audit `''`/`0` comparisons, reinstall the skill with `--force`. I checked each command against `safe-ts --help`. The docs use `<version>` so the examples don't go stale. ## What is still reported - Real casts, including one inside a template's `${...}`, and `as unknown as` / `as never` / `as any`. - The global `fetch` through any spelling the census can see, an aliased global (`const fetch = globalThis.fetch`), axios and XMLHttpRequest. - Fixture `src/sim.ts` covers string/template English (not counted), a multi-line key remap (not counted) and a template cast (counted). The new `src/requests.ts` covers an imported pack `fetch` (not counted), a method (not counted) and `globalThis.fetch` (counted). ## Tests - `packages/safe-ts-skill/test/skill.test.ts`: 11 pass. - New: the census's checker counts equal one `safe-ts check src --idiomatic --json` run, per rule and file. - The lint test now enables `idiomatic` and also runs `safe-ts check --idiomatic` on `census.mjs`, `safe-ts.mjs` and `install.mjs` (expects `[]`). Put back on main's census, it reports `no-swallowed-error`. - `cargo nextest run -p safe_ts_core --test docs`: 4 pass. `npm run test:docs`: builds. - With the adopter's own lint config (type-aware, every rule an error, `.claude/**` un-ignored), `vp lint .claude` is clean. - Rules weren't touched, so I didn't run the rewrites/soundness suites. ## Adopter tree, before → after | | main | this branch | `safe-ts check apps packages scripts --idiomatic` | |---|---|---|---| | `no-optional-field` | 1146 | 821 | 821 | | `unused-code` | 13 | 83 | 83 | | all rules, per rule and file | differ | identical (1187 rule×file rows) | — | | `as-cast` | 11 | 1 (the real cast) | | | `raw-fetch` | 14 | 2 (an aliased global in a test helper; a call through a parameter named `fetch`) | | | `module-let` | 1 | 1 | | On this repo's own `packages examples docs`, every hit the new census drops is a false positive: test names, a string holding an import line, fixture cases, and a pack `fetch` import. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Migration skill census: one checker run, casts and fetch from code, scripts pass the idiomatic rules
Some checks failed
Benchmarks / bench (pull_request) Successful in 4m10s
Tests / test (pull_request) Failing after 15m51s
4a606b58de
The census ran `safe-ts check` over its file list in parts, so the whole-program rules
(no-optional-field, unused-code) saw only a part; it now runs once over the given directories
and its counts per rule and file equal `safe-ts check <dirs> --idiomatic`. as-cast/double-cast
look at code with strings, templates, regex literals and comments blanked, and at mapped-type
key remapping over several lines; raw-fetch skips a fetch the file imports by name and a
method named fetch, and counts globalThis.fetch. The git ls-files fallback no longer swallows
an error in a catch (no-swallowed-error with idiomatic on); the skill test lints with the
idiomatic rules and runs safe-ts check on the scripts. The upgrade steps name safe-ts fix and
put migrate mut first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge main into census-skill-upgrade
Some checks failed
Tests / test (pull_request) Has been cancelled
Benchmarks / bench (pull_request) Has been cancelled
0ba5919d36
Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee deleted branch census-skill-upgrade 2026-11-24 14:08:02 +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!157
No description provided.