safe-ts-ignore of a whole-program rule: not called unused by the oxlint plugin and the editor #159

Merged
sionzee merged 2 commits from evobug/plugin-whole-program-ignores into main 2026-11-24 14:07:06 +01:00
Owner

What was wrong

safe-ts check and the oxlint plugin disagreed about // safe-ts-ignore for the rules only the whole program shows (PROGRAM_RULES: no-optional-field, unused-code, inline-member-set, constructor-calls-override, path-sink, unknown-event, unmatched-event). The plugin (and the editor) check one file and its imports and never report those rules. So every ignore of one looked unused there, while safe-ts check needed it. Both couldn't be satisfied: an adopter had to turn no-optional-field off for the file with an "overrides" entry.

Reduced:

// src/other.ts: nothing in the program parses `Local` as JSON
export type Local = {
  // safe-ts-ignore no-optional-field: kept as written for the wire
  readonly tag?: string;
};

On main, safe-ts check src --idiomatic needs this ignore (without it, no-optional-field is reported). The plugin reports it as unused safe-ts-ignore: nothing on line 3 is reported by no-optional-field.

What changed

  • Run now records whether it covers the whole program (whole_program, set in program_wide). Where it doesn't (check_file: the plugin, the editor), an ignore of a rule in PROGRAM_RULES isn't judged unused. The rule property comes from the core's existing PROGRAM_RULES. The plugin itself is unchanged.
  • safe-ts check hasn't changed: it still reports a stale ignore of those rules. For example, a field that a parseJson<T> in another file makes a JSON key, so the ignore silences nothing.
  • The other problems of an ignore are still reported everywhere: a missing reason, an unknown rule, and the stale half of no-null, no-optional-field.

Opposite direction (item 3)

I compared the plugin path (Checker.checkFile per file, through the addon) with safe-ts check apps packages scripts --idiomatic on the adopter's tree. Every finding outside PROGRAM_RULES was compared, safe-ts-ignore included, across 813 files. Result: 0 differences either way. In the code, the only other whole-program inputs are the member names, brand sinks and class slot names. The member names only skip resolutions that would find nothing. The brand sinks are listed from the project in both paths. So I found no finding the plugin reports and check doesn't. check_file_matches_check_entry keeps guarding this on every fixture.

Checking a subset (safe-ts check src/types.ts) can judge no-optional-field differently from checking the directory. That happens when the parseJson<T> is in a file the entries don't reach. check already warns there that files under the entries' directories aren't checked, so I left it.

Tests

  • Fixture optional_field/ignored.ts, with Batch in payloads.ts:
    • an ignore check needs, which is silenced;
    • a stale one on a type that a parseJson<Batch> in another file nests, which check reports;
    • an unignored field next to them, still reported;
    • a stale no-null ignore, reported in both paths.
  • check_file_matches_check_entry now also leaves out check's "unused" for program rules. check_file still has to match everything else, and it fails if the editor calls such an ignore unused again.
  • packages/oxlint-plugin-safe-ts/test/ignores.test.ts, in the plugin's own test setup. Both tests fail on main's addon and pass with this change.
  • cargo nextest run --workspace --cargo-profile fast: 412/412 pass. npm run test:soundness: the escaping classes are exactly escaping.txt. npm run test:docs: passes. Plugin tests: 9/9 pass.
  • npm run test:rewrites (full) fails, already on main: new missing-mut hoist-const is listed 226 and found 229, and text aliased-mut call is listed 14 and found 16. The report puts all 5 cases in mut_two_names/main.ts, the fixture #150 added without updating misses.txt. This change doesn't move any count, so I left misses.txt alone. It needs its own fix, and whoever owns it decides whether those new missing-mut cases are acceptable.

Adopter tree

I put a // safe-ts-ignore no-optional-field: … above each of the 19 lines safe-ts check reports in the file where the adopter used an "overrides" entry, then ran the plugin path:

ignores reported unused by the plugin
main 19 19
this PR 19 0

Docs: docs/rules/safe-ts-ignore.md, docs/rules/no-optional-field.md, the "Ignoring one finding" section of the adoption guide, and CHANGELOG (Fixed).

🤖 Generated with Claude Code

## What was wrong `safe-ts check` and the oxlint plugin disagreed about `// safe-ts-ignore` for the rules only the whole program shows (`PROGRAM_RULES`: `no-optional-field`, `unused-code`, `inline-member-set`, `constructor-calls-override`, `path-sink`, `unknown-event`, `unmatched-event`). The plugin (and the editor) check one file and its imports and never report those rules. So every ignore of one looked unused there, while `safe-ts check` needed it. Both couldn't be satisfied: an adopter had to turn `no-optional-field` off for the file with an `"overrides"` entry. Reduced: ```ts // src/other.ts: nothing in the program parses `Local` as JSON export type Local = { // safe-ts-ignore no-optional-field: kept as written for the wire readonly tag?: string; }; ``` On main, `safe-ts check src --idiomatic` needs this ignore (without it, `no-optional-field` is reported). The plugin reports it as `unused safe-ts-ignore: nothing on line 3 is reported by no-optional-field`. ## What changed - `Run` now records whether it covers the whole program (`whole_program`, set in `program_wide`). Where it doesn't (`check_file`: the plugin, the editor), an ignore of a rule in `PROGRAM_RULES` isn't judged unused. The rule property comes from the core's existing `PROGRAM_RULES`. The plugin itself is unchanged. - `safe-ts check` hasn't changed: it still reports a stale ignore of those rules. For example, a field that a `parseJson<T>` in another file makes a JSON key, so the ignore silences nothing. - The other problems of an ignore are still reported everywhere: a missing reason, an unknown rule, and the stale half of `no-null, no-optional-field`. ## Opposite direction (item 3) I compared the plugin path (`Checker.checkFile` per file, through the addon) with `safe-ts check apps packages scripts --idiomatic` on the adopter's tree. Every finding outside `PROGRAM_RULES` was compared, `safe-ts-ignore` included, across 813 files. Result: **0 differences either way.** In the code, the only other whole-program inputs are the member names, brand sinks and class slot names. The member names only skip resolutions that would find nothing. The brand sinks are listed from the project in both paths. So I found no finding the plugin reports and `check` doesn't. `check_file_matches_check_entry` keeps guarding this on every fixture. Checking a subset (`safe-ts check src/types.ts`) can judge `no-optional-field` differently from checking the directory. That happens when the `parseJson<T>` is in a file the entries don't reach. `check` already warns there that files under the entries' directories aren't checked, so I left it. ## Tests - Fixture `optional_field/ignored.ts`, with `Batch` in `payloads.ts`: - an ignore `check` needs, which is silenced; - a stale one on a type that a `parseJson<Batch>` in another file nests, which `check` reports; - an unignored field next to them, still reported; - a stale `no-null` ignore, reported in both paths. - `check_file_matches_check_entry` now also leaves out `check`'s "unused" for program rules. `check_file` still has to match everything else, and it fails if the editor calls such an ignore unused again. - `packages/oxlint-plugin-safe-ts/test/ignores.test.ts`, in the plugin's own test setup. Both tests fail on main's addon and pass with this change. - `cargo nextest run --workspace --cargo-profile fast`: 412/412 pass. `npm run test:soundness`: the escaping classes are exactly `escaping.txt`. `npm run test:docs`: passes. Plugin tests: 9/9 pass. - `npm run test:rewrites` (full) **fails, already on main**: `new missing-mut hoist-const` is listed 226 and found 229, and `text aliased-mut call` is listed 14 and found 16. The report puts all 5 cases in `mut_two_names/main.ts`, the fixture #150 added without updating `misses.txt`. This change doesn't move any count, so I left `misses.txt` alone. It needs its own fix, and whoever owns it decides whether those `new missing-mut` cases are acceptable. ## Adopter tree I put a `// safe-ts-ignore no-optional-field: …` above each of the 19 lines `safe-ts check` reports in the file where the adopter used an `"overrides"` entry, then ran the plugin path: | | ignores | reported unused by the plugin | |---|---|---| | main | 19 | 19 | | this PR | 19 | 0 | Docs: `docs/rules/safe-ts-ignore.md`, `docs/rules/no-optional-field.md`, the "Ignoring one finding" section of the adoption guide, and CHANGELOG (Fixed). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
safe-ts-ignore of a rule only the whole program shows: not called unused by the oxlint plugin and the editor
Some checks failed
Benchmarks / bench (pull_request) Successful in 4m4s
Tests / test (pull_request) Failing after 29m31s
79ff1f3105
The oxlint plugin and the editor check one file and its imports and never report the rules in
PROGRAM_RULES (no-optional-field, unused-code, inline-member-set, constructor-calls-override,
path-sink, unknown-event, unmatched-event). Every ignore of one looked unused there, while
`safe-ts check` needed it, so the two couldn't both be satisfied. The run now knows whether it
covers the whole program (`Run::whole_program`, set by `program_wide`); where it doesn't, an
ignore of a program rule isn't judged unused. `safe-ts check` still reports a stale one, and
every other problem of an ignore is reported everywhere.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge main into evobug/plugin-whole-program-ignores
Some checks failed
Tests / test (pull_request) Has been cancelled
Benchmarks / bench (pull_request) Has been cancelled
ca19449025
sionzee deleted branch evobug/plugin-whole-program-ignores 2026-11-24 14:07:06 +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!159
No description provided.