safe-ts-ignore of a whole-program rule: not called unused by the oxlint plugin and the editor #159
Loading…
Reference in a new issue
No description provided.
Delete branch "evobug/plugin-whole-program-ignores"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What was wrong
safe-ts checkand the oxlint plugin disagreed about// safe-ts-ignorefor 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, whilesafe-ts checkneeded it. Both couldn't be satisfied: an adopter had to turnno-optional-fieldoff for the file with an"overrides"entry.Reduced:
On main,
safe-ts check src --idiomaticneeds this ignore (without it,no-optional-fieldis reported). The plugin reports it asunused safe-ts-ignore: nothing on line 3 is reported by no-optional-field.What changed
Runnow records whether it covers the whole program (whole_program, set inprogram_wide). Where it doesn't (check_file: the plugin, the editor), an ignore of a rule inPROGRAM_RULESisn't judged unused. The rule property comes from the core's existingPROGRAM_RULES. The plugin itself is unchanged.safe-ts checkhasn't changed: it still reports a stale ignore of those rules. For example, a field that aparseJson<T>in another file makes a JSON key, so the ignore silences nothing.no-null, no-optional-field.Opposite direction (item 3)
I compared the plugin path (
Checker.checkFileper file, through the addon) withsafe-ts check apps packages scripts --idiomaticon the adopter's tree. Every finding outsidePROGRAM_RULESwas compared,safe-ts-ignoreincluded, 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 andcheckdoesn't.check_file_matches_check_entrykeeps guarding this on every fixture.Checking a subset (
safe-ts check src/types.ts) can judgeno-optional-fielddifferently from checking the directory. That happens when theparseJson<T>is in a file the entries don't reach.checkalready warns there that files under the entries' directories aren't checked, so I left it.Tests
optional_field/ignored.ts, withBatchinpayloads.ts:checkneeds, which is silenced;parseJson<Batch>in another file nests, whichcheckreports;no-nullignore, reported in both paths.check_file_matches_check_entrynow also leaves outcheck's "unused" for program rules.check_filestill 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 exactlyescaping.txt.npm run test:docs: passes. Plugin tests: 9/9 pass.npm run test:rewrites(full) fails, already on main:new missing-mut hoist-constis listed 226 and found 229, andtext aliased-mut callis listed 14 and found 16. The report puts all 5 cases inmut_two_names/main.ts, the fixture #150 added without updatingmisses.txt. This change doesn't move any count, so I leftmisses.txtalone. It needs its own fix, and whoever owns it decides whether thosenew missing-mutcases are acceptable.Adopter tree
I put a
// safe-ts-ignore no-optional-field: …above each of the 19 linessafe-ts checkreports in the file where the adopter used an"overrides"entry, then ran the plugin path: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