Rule precision from a 0.4.0 upgrade, and std's latest() #92
Loading…
Reference in a new issue
No description provided.
Delete branch "rule-precision-0-4"
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?
An adopter's upgrade to 0.4.0 turned up six precision problems and one missing std helper. I reproduced each one with a probe before changing anything. Item 5 was already handled, so it only gets better help text and docs.
What changed
catch-on-resultreported atrythat is aPropagateErrorboundary.readSave/migratereturn aResultand also throwCorruptSave, andtransitionWorldthrowsSimFault. The PropagateError map already showed these kinds caught in thattry, but the rule only asked whether the callee returns aResult. The rule now skips atrywhen a call in it propagates a tracked kind that thiscatchtakes (fn_propagation_with+is_caught, the same logic the map uses). It still reports atryaround nothing that throws, and acatchthat lets the kind through (if (e instanceof Other) ...; throw e).bounded-concurrency:keysOf(FROZEN)was flagged,Object.entries(FROZEN)wasn't. The rule page says the keys of a fixed table are bounded, sokeysOfwas the inconsistent one. std'skeysOf(imported by name or throughimport * as dict) over a frozen oras consttable now counts as fixed length.keysOf(param)is still reported.q-needs-result-returnignored the return type of the function a literal is returned from. Methods weren't the problem:const x: Fake = { async fetch() {...} }already worked. The gap wasreturn { ... }. A returned literal (from areturnor an arrow's expression body) now gets its callbacks' context from the declared return type, throughPromise<T>for anasyncfunction. I also fixed a nearby hole: a callback that declares its own return type ((a): number => { q(...) }inside an annotatedconst) used to be excused by the outer context. It is now checked against its own type.no-mutable-global: an emitter subscribed with a listener passed in.Set.addandpushinto a module array were already caught, and so was a listener written in place.target.addEventListener("x", f)/bus.on("x", f)withfa parameter wasn't. The old fixture even excused it on purpose ("can be removed withoff"), but nothing checked that anything removed it. Such a subscription is now reported (alsothis.onTick.bind(this)), except:off/removeListener/removeEventListener). The listener is matched by its binding (a parameter of another function with the same name doesn't count) or, forthis.onTick, as written;subscribe(f)returns is kept;Subscribing at module level, as in a startup-only
new EventTarget(), was never reported and still isn't.no-for-inoverObject.create(null)dictionaries: already fixed in 0.3.0 (#70). Both a visible null-prototype binding and theif (!Object.hasOwn(o, k)) continue;guard are accepted. The premise thatfor...inover a null-prototype object doesn't allocate is wrong. The rule page's own measurements (and V8) show thatfor...inover a dictionary-mode object collects its keys into a new array on every walk (97 B for 4 keys). So there is no allocation-free option, and a type can't prove an object has no prototype. A library's dictionaries are made inside the library, so the checker can't see them being made. I changed only the help and the page: the help now names thehasOwnguard as the form for a library's dictionary (no more memory thanfor...in), and steers toObject.keys+ lookup rather thanObject.values/entries. The page has a section with an example.stable-shapewith three or more conditional spreads. It is not loosened. The finding now says "This literal leaves out N keys with conditional spreads: up to 2^N shapes ...". The help names the form: every key written, declaredkey: Option<T>. The rule page has a ✅ example of it. "Assigned after the literal" is not a valid alternative. It makes the same number of shapes, and the rule already reportso.x = ...on a literal withoutx. The help and the skill say so.std
latest(work, signal?)inpackages/std/src/async.ts, with aSupersedederror class. Its semantics followuseTask:run(...args)aborts the previous run's signal and gives the new run a fresh one;workresolved to, or toerr(Superseded)when a newer run orabort()came first, whatever the older run resolved or rejected with;runrejects with it;signalaborts the run in progress and makes later runs resolve toSupersededwithout starting.latest-wins-counternow nameslatestin a file that imports neither Vue/React/Pinia nor their SAFE-TS packages, anduseTask(mentioninglatest) otherwise.unused-task-signalalso checkslatestcallbacks.Docs: the rule pages for all of the above,
docs/guide/async.md(new "Latest run wins" section),docs/guide/std-helpers.md, the rule tables indocs/README.mdand the adoption guide, the skill (tool-gaps.md,patterns-core.md,patterns-vue.md,census.md,final-pass.md), and CHANGELOG.Tested
safe-ts checkon small programs).idiomatic_rules/boundary.ts(withpropagates/caughtannotations) andidiomatic_rules/latest.ts; new cases inbounded_concurrency,question,shapesandsubscribers(the old "named listener" exemption became the cases above).latesttests inpackages/std/test/async.test.ts.cargo nextest run: 280 passed.npm run test:std: 371 passed.node scripts/docs-typecheck.mjs: 611 examples compile. The docs test (734 examples, bad/good blocks) passes.npm run typecheckpasses.safe-ts check packages/std/src/async.ts: no problems.Left out
PropagateErrorthrown insidelatest's work is reported as escaping a callback (uncaught-propagation), not followed throughrun's rejection. That is conservative, and the docs say to return the failure as anErr. ModellinglatestlikemapLimitin the propagation pass would be a separate change.GraphicsContextextends eventemitter3'sEventEmitterin its.d.ts, but the checker only follows packs' class chains, so a module-level one still needs"safe-ts": { "emitters": ["pixi.js GraphicsContext"] }to be seen. Reading emitter ancestry from a package's declarations would be a separate change.const search = latest(...)called from functions isn't reported byno-mutable-global, because the checker doesn't look into std's closures. The docs examples createlatestinside the function that owns it.Created with Claude Opus 5.5 in Claude Code.
1fee685904c48408c6c4