Migration skill: scripts pass the lint preset, census precision, an upgrade path #90

Merged
sionzee merged 1 commit from skill-upgrade-and-census into main 2026-11-20 16:28:04 +01:00
Owner

Problem

An adopter upgraded a 729-file project from 0.3.0 to 0.4.0 and reported four problems with the migration skill:

  1. The skill's scripts failed the preset they ship with. A project that lints every file got errors in .claude/skills/safe-ts-migrate/scripts/census.mjs: unhandled-failure (on readFileSync, statSync, JSON.parse and new RegExp), no-object-dictionary ×9, and a sort without a comparator. They had to exclude .claude/** from lint.
  2. as-cast counted renames. Most of the 42 hits were renames in import lists that span several lines ( type Building as SimBuilding,) and mapped-type key remapping ([E in AdminEvent as E['type']]).
  3. module-let and minus-one-sentinel were noisy. 85 of the 86 module-let hits were test files' let errors that beforeEach resets. minus-one-sentinel couldn't tell a named index sentinel (const NONE = -1, used in typed arrays) from "not found".
  4. No upgrade path. Changing every pin to 0.4.0 and running npm install stopped with ERESOLVE.

Solution

  • Scripts pass the lint preset. census.mjs and install.mjs now pass oxlint with the preset (safe-ts.mjs already did). The test also turns on the Node pack, which is where readFileSync and statSync get reported.
    • SAFE-TS isn't installed yet when the scripts run, so they can't import std. Each call that can fail goes through a small orExit(what, step). It prints census: <what failed>: <why> and exits 2.
    • Dictionaries are Maps (a Counts class); the JSON report and the baseline format don't change. Every sort has a comparator.
    • Baseline counts are checked: a value that isn't a whole number stops the gate with a message instead of becoming NaN.
    • No rule needed an ignore comment.
    • The census never scans the skill's own folder (only when SKILL.md is next to scripts/, so a copy in the project's scripts/ doesn't exclude the project).
  • as-cast / double-cast:
    • Lines inside an import { / export { / export type { list that spans several lines are skipped. export const x = { doesn't count as a list.
    • The as of [K in Keys as NewKey] is removed from the line before matching.
  • module-let skips test files. I chose skipping over a separate count. A test file is what the checker calls one: *.test.* / *.spec.*, in a test, tests, __tests__ or __mocks__ folder, or importing a test runner. Each test file is its own module, so its let isn't state the app shares, and the checker's no-mutable-global still reports it. Documented in references/census.md.
  • minus-one-sentinel:
    • A named sentinel is counted once, at its declaration. That includes export const, static readonly, a type annotation, or as const (the last two weren't counted at all before).
    • Uses by name (=== NONE, .fill(NONE)) aren't counted.
    • The way to "mark it once" is to name it and use the name: a literal -1 that means the same thing still counts, and that is the place to fix.
    • New section "A named sentinel" in references/census.md.
  • "Upgrading between versions":
    • Added to SKILL.md (after Workflow; its description now also says "upgrade") and as a section at the end of docs/guide/migration-skill.md.
    • Steps: bump every @evobug_com package together, then take the census. Apply fixes one rule at a time and review each, with the strict-truthiness / x?: string / x !== '' case spelled out. Audit '' and 0 comparisons. Reinstall the skill with --force.
    • The ERESOLVE remedy: install all the packages in one npm install [email protected] [email protected] … (npm keeps each in its current dependency field), or drop their lockfile entries.
    • safe-ts fix <rule> is mentioned only as "if your version has it".
    • A first bullet in adoption.md's "Upgrading and bulk fixes" points there.
  • Peer ranges unchanged. ^0.4.0 already means >=0.4.0 <0.5.0 for 0.x, which is right for packages released together. The ERESOLVE came from the lockfile still holding an old version, not from the ranges.

I kept clear of the spots PR #89 edits: the top of "Rules for the whole migration", workflow step 5, the references table, review-checklist, templates, and step 5 and the file table of migration-skill.md. CHANGELOG will probably need a small merge under Unreleased. The string-if-chain pattern is unchanged.

Testing

  • node --test --import ./packages/safe-ts-transform/register.mjs packages/safe-ts-skill/test/skill.test.ts: 10 pass. New tests:
    • The scripts and the installer in a temp project, with the preset and the Node pack, through oxlint --deny-warnings: clean. A planted readFileSync in the same folder is reported, which shows the run really lints the files.
    • The census skips a .ts file put inside the skill's folder.
    • A baseline that isn't JSON, or that holds "two", gives a census: … message and exit 2.
    • New fixture src/sim.ts: renames in a multi-line import and export list, a mapped-type remap, and const NONE = -1 with .fill(NONE) / === NONE. user.spec.ts gets a top-level let. Pattern counts asserted.
  • Before the change, oxlint with the preset and the Node pack reported 26 problems in these scripts. The old census counted the three renames in sim.ts and the spec file's let; the new one counts none of them.
  • I ran the old and the new census on packages examples docs. Only as-cast (219 → 213) and module-let (15 → 5) changed. Each place removed is a rename, a mapped-type remap, or a file under a test folder. Feature counts are the same.
  • npm run test:std: 370 pass.
  • cargo nextest run -p safe_ts_core --test docs: 3 pass.
  • node scripts/docs-typecheck.mjs: 605 examples compile.
  • Not run: the VitePress build (npm run test:docs).

Left out

  • The typescript/require-array-sort-compare rule needs oxlint's type-aware mode. I didn't run that mode; instead every sort in the scripts has a comparator.
  • I didn't find a safe single-rule autofix command for the docs. While testing I saw that oxlint --fix -A all -D safe-ts/<rule> doesn't turn off the plugin's other rules, and that strict-truthiness has no autofix, so --fix doesn't apply it. The upgrade steps point to the editor's quick fixes or safe-ts fix <rule> instead. That command belongs to the other lane.

Created with Claude Opus 5.5 in Claude Code.

## Problem An adopter upgraded a 729-file project from 0.3.0 to 0.4.0 and reported four problems with the migration skill: 1. **The skill's scripts failed the preset they ship with.** A project that lints every file got errors in `.claude/skills/safe-ts-migrate/scripts/census.mjs`: `unhandled-failure` (on `readFileSync`, `statSync`, `JSON.parse` and `new RegExp`), `no-object-dictionary` ×9, and a sort without a comparator. They had to exclude `.claude/**` from lint. 2. **`as-cast` counted renames.** Most of the 42 hits were renames in import lists that span several lines (` type Building as SimBuilding,`) and mapped-type key remapping (`[E in AdminEvent as E['type']]`). 3. **`module-let` and `minus-one-sentinel` were noisy.** 85 of the 86 `module-let` hits were test files' `let errors` that `beforeEach` resets. `minus-one-sentinel` couldn't tell a named index sentinel (`const NONE = -1`, used in typed arrays) from "not found". 4. **No upgrade path.** Changing every pin to 0.4.0 and running `npm install` stopped with `ERESOLVE`. ## Solution - **Scripts pass the lint preset.** `census.mjs` and `install.mjs` now pass oxlint with the preset (`safe-ts.mjs` already did). The test also turns on the Node pack, which is where `readFileSync` and `statSync` get reported. - SAFE-TS isn't installed yet when the scripts run, so they can't import std. Each call that can fail goes through a small `orExit(what, step)`. It prints `census: <what failed>: <why>` and exits 2. - Dictionaries are `Map`s (a `Counts` class); the JSON report and the baseline format don't change. Every sort has a comparator. - Baseline counts are checked: a value that isn't a whole number stops the gate with a message instead of becoming `NaN`. - No rule needed an ignore comment. - The census never scans the skill's own folder (only when `SKILL.md` is next to `scripts/`, so a copy in the project's `scripts/` doesn't exclude the project). - **`as-cast` / `double-cast`:** - Lines inside an `import {` / `export {` / `export type {` list that spans several lines are skipped. `export const x = {` doesn't count as a list. - The `as` of `[K in Keys as NewKey]` is removed from the line before matching. - **`module-let` skips test files.** I chose skipping over a separate count. A test file is what the checker calls one: `*.test.*` / `*.spec.*`, in a `test`, `tests`, `__tests__` or `__mocks__` folder, or importing a test runner. Each test file is its own module, so its `let` isn't state the app shares, and the checker's `no-mutable-global` still reports it. Documented in `references/census.md`. - **`minus-one-sentinel`:** - A named sentinel is counted once, at its declaration. That includes `export const`, `static readonly`, a type annotation, or `as const` (the last two weren't counted at all before). - Uses by name (`=== NONE`, `.fill(NONE)`) aren't counted. - The way to "mark it once" is to name it and use the name: a literal `-1` that means the same thing still counts, and that is the place to fix. - New section "A named sentinel" in `references/census.md`. - **"Upgrading between versions":** - Added to `SKILL.md` (after Workflow; its description now also says "upgrade") and as a section at the end of `docs/guide/migration-skill.md`. - Steps: bump every `@evobug_com` package together, then take the census. Apply fixes one rule at a time and review each, with the `strict-truthiness` / `x?: string` / `x !== ''` case spelled out. Audit `''` and `0` comparisons. Reinstall the skill with `--force`. - The `ERESOLVE` remedy: install all the packages in one `npm install [email protected] [email protected] …` (npm keeps each in its current dependency field), or drop their lockfile entries. - `safe-ts fix <rule>` is mentioned only as "if your version has it". - A first bullet in adoption.md's "Upgrading and bulk fixes" points there. - **Peer ranges unchanged.** `^0.4.0` already means `>=0.4.0 <0.5.0` for 0.x, which is right for packages released together. The `ERESOLVE` came from the lockfile still holding an old version, not from the ranges. I kept clear of the spots PR #89 edits: the top of "Rules for the whole migration", workflow step 5, the references table, review-checklist, templates, and step 5 and the file table of migration-skill.md. CHANGELOG will probably need a small merge under Unreleased. The `string-if-chain` pattern is unchanged. ## Testing - `node --test --import ./packages/safe-ts-transform/register.mjs packages/safe-ts-skill/test/skill.test.ts`: 10 pass. New tests: - The scripts and the installer in a temp project, with the preset and the Node pack, through `oxlint --deny-warnings`: clean. A planted `readFileSync` in the same folder is reported, which shows the run really lints the files. - The census skips a `.ts` file put inside the skill's folder. - A baseline that isn't JSON, or that holds `"two"`, gives a `census: …` message and exit 2. - New fixture `src/sim.ts`: renames in a multi-line import and export list, a mapped-type remap, and `const NONE = -1` with `.fill(NONE)` / `=== NONE`. `user.spec.ts` gets a top-level `let`. Pattern counts asserted. - Before the change, oxlint with the preset and the Node pack reported 26 problems in these scripts. The old census counted the three renames in `sim.ts` and the spec file's `let`; the new one counts none of them. - I ran the old and the new census on `packages examples docs`. Only `as-cast` (219 → 213) and `module-let` (15 → 5) changed. Each place removed is a rename, a mapped-type remap, or a file under a test folder. Feature counts are the same. - `npm run test:std`: 370 pass. - `cargo nextest run -p safe_ts_core --test docs`: 3 pass. - `node scripts/docs-typecheck.mjs`: 605 examples compile. - Not run: the VitePress build (`npm run test:docs`). ## Left out - The `typescript/require-array-sort-compare` rule needs oxlint's type-aware mode. I didn't run that mode; instead every sort in the scripts has a comparator. - I didn't find a safe single-rule autofix command for the docs. While testing I saw that `oxlint --fix -A all -D safe-ts/<rule>` doesn't turn off the plugin's other rules, and that `strict-truthiness` has no autofix, so `--fix` doesn't apply it. The upgrade steps point to the editor's quick fixes or `safe-ts fix <rule>` instead. That command belongs to the other lane. Created with Claude Opus 5.5 in Claude Code.
Migration skill: scripts pass the lint preset, census precision, an upgrade path
All checks were successful
Benchmarks / bench (pull_request) Successful in 3m41s
63c867bc2a
- census.mjs and install.mjs pass oxlint with the SAFE-TS preset and the Node pack: failing
  calls go through orExit (names what failed, exits 2), dictionaries are Maps, sorts have
  comparators, baseline counts are checked. The census never scans the skill's own folder.
  A test lints the scripts in a project with the preset.
- as-cast/double-cast skip renames in import/export lists over several lines and mapped-type
  key remapping; module-let skips test files; minus-one-sentinel counts a named sentinel
  (const NONE = -1) once, at its declaration. Fixture cases for each.
- "Upgrading between versions" in SKILL.md and the migration skill guide, with the ERESOLVE
  remedy; a pointer from adoption.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee force-pushed skill-upgrade-and-census from 63c867bc2a
All checks were successful
Benchmarks / bench (pull_request) Successful in 3m41s
to 7bb9e271eb
All checks were successful
Benchmarks / bench (pull_request) Successful in 3m53s
2026-11-20 16:27:50 +01:00
Compare
sionzee deleted branch skill-upgrade-and-census 2026-11-20 16:28:04 +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!90
No description provided.