One spelling for every rule: a harness that rewrites each fixture 39 ways, and a normalisation that takes 2,094 silent sites down to 300 #134
Loading…
Reference in a new issue
No description provided.
Delete branch "spelling-harness"
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?
Based on
after-await(#133), and contains it: the diff shown is this piece alone.A rule recognises the code it was written against. Written another way, the same code often passed in silence:
Each line is one program spelled several ways; a rule that reports the first form should report them all. An agent does not pick spellings to dodge a rule, but it produces every one of them, and each rule had its own, narrower idea of what a call or a type looks like. Nobody had measured how often that mattered.
The harness
crates/safe_ts_core/tests/rewrites.rsrewrites every fixture one meaning-preserving way at one site at a time (39 transformations: aconstcopy of a callee or a receiver, a namespace import,x?.m(),x["m"](),.calland.apply, a re-export, an arrow for a declaration and back, a callback by name, a value through aconst, destructuring, a type alias,Readonly<T>,for...offorforEach,if/elsefor?:, and more), keeps the variantstscaccepts, and compares each variant's findings with the fixture's, line by line. About 43,000 variants. A finding the variant loses is a miss.At the start: 2,094 sites where a rule went silent, across nearly every rule.
The count per rule and transformation is a ratchet in
tests/rewrites/misses.txt, each line with its reason. The test fails when a count differs either way, so a new rule arrives with its spelling gaps written down, and a fix takes its line off. The normal run takes about 20 seconds;npm run test:rewriteschecks every site and runs in CI.The fix: one spelling, for every rule
spelling::normalizerewrites the parsed tree once, before the semantic analysis, so that every rule reads the same thing:o["m"]iso.m; parentheses are gone;f.call(t, a)andf.apply(t, [a])aref(a);constcopy of a name are the name;x?.m()isx.m()wherexcannot be absent by how it is written;x = x + eisx += e.On the same fixtures, 2,094 sites became 300. On today's tree, with the fixtures of the 26 rules added since, the list holds 364 (and 159 more where the finding lost is away from the rewritten line).
What the user wrote still decides three things, read off the tree as parsed, each with a test that compares both trees on every fixture:
unused-codeandunused-privatecount the references that are written; an opened alias or a replaced copy is still a use);Found on the way
unsafe(() => ...)around a call that containsawait. Found by applying every fix to every variant; it isunsafeAsync(async () => ...)now..runAllTimers(, formut(, forPromisein an annotation, a receiver keyed by its text. Each now reads the tree.Evidence
no-param-mutation76 to 168 andprefer-constructor-tag4 to 181, every one in code that imports through a re-exporting index (13 read by me, all real; the implementer checked all by pattern and read 36);wide-param+2, a parameter read only through a deadconstcopy; onejson-typemessage that now names the module a type really comes from. Nothing else moves, the three examples are identical.safe-ts emitgives byte-identical output on the demo, on std's tests and on a file full of rewritten spellings.What turns red on upgrade
Rules now see code they missed. A project that imports through an index file, uses namespace imports, or copies functions into
consts will get findings on code that passed. On the adopter that is 271, all in two rules, all through one index.What stays unseen
The list says, line by line. The large groups:
const r = f(); use(r)where the rule readsuse(f())): 26 sites formust-use-result, 16 forbounded-concurrency, 15 foraliased-mut. Needs each rule to follow the binding, not a rewrite.x?.m()where only the type saysxis there: the tree cannot tell.const s = a.b; s.m()), and rules with an import lookup of their own (six lines).Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review, acceptance tests and the merges) in Claude Code.