Code nothing refers to, branches already decided, event names that match at neither end: five rules from the whole program #130
Loading…
Reference in a new issue
No description provided.
Delete branch "whole-program-reach"
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
sinks-and-brands(#129), and contains it and #128: the diff shown is this piece alone.Some defects are in no single file. An agent that writes a new function rarely deletes the old one; a listener waits for a name the other end stopped emitting; a branch stays behind after its case was handled. Each of these passed
tscstrict,safe-ts check --deny-warningsand oxlint with the preset:Five rules
unused-codeunused-privateprivateor#member nothing in its class uses, a private field written and never read, a private member read only by unused private membersunreachable-codepanic,unreachable,process.exit(), a function declarednever, imported ones too); a branch the subject's closed type has already decided, also aftertypeof,instanceof,=== undefined,Array.isArrayandintests that take every kind the written type hasunknown-eventunmatched-eventWhat counts as used is what a file's module code refers to, and every export the outside can reach: an entry named on the command line, a file nothing imports, one loaded by
import(), a worker orimport.meta.glob, what a package.json'smain/exports/binname, tool config files, Vue components, and what a test or script of the same package imports. It stands on a per-file index of resolved references (from oxc's scope analysis) joined once in the whole-program pass.safe-ts fix unused-code <dirs>deletes what nothing refers to at all; run it again for what a deletion leaves.Event names are data. The browser pack lists
lib.dom.d.ts's event maps and the Node pack@types/node's, each checked against the installed version by a test. An emitter of the program's own (a module-level one, a class extendingEventEmitterorEventTarget, a field holding one) is matched end to end; the listener side is reported only where nothing outside the program can emit on it.The oxlint preset now names what one file shows of dead code (
no-unused-vars,no-unreachable,no-constant-condition,no-duplicate-case,no-dupe-else-if): they were on only through oxlint's default category, so a project that set its own categories lost them without a word.Evidence
#andprivatemembers; a listener on an emitter nothing else can reach against one that is handed out;typeof/instanceof/=== undefinedchains with a dead fallback; misspelt Node event names on aServer, a stream andprocess. The first round missed the listener side,#members, type tests and Node's events; all four were added.unused-codefindings checking its directories (46 from its entries) and oneunused-private, every one read and dead: copies of functions a shared package had taken over, constants and helpers nothing calls any more, and the chains only those used.unreachable-code,unknown-eventandunmatched-event: none, with 62 listeners on Node objects checked. No count of any other rule changes there or on the three example projects (the demo gains 4unused-code, all real).unused-codeon, of which about 30 ms is the reference index and a scan of 175 files around the program; with the rule off, 5 ms. These are the implementer's numbers; my own rerun was on a loaded machine and showed no difference outside its noise. The scan runs only when the rule is on for some file, parses each file once per content, and has a ceiling in the work-count test (outside_files_parsed).What turns red on upgrade
unreachable-code,unknown-eventandunmatched-eventare errors. Writeunreachable(x)for a fallback after every member of a closed type; delete code afterpanic(...); use one constant for an event name at both ends.no-unused-varsstays a warning.unused-codeandunused-privateadd warnings; the baseline holds their count.What stays unseen
unused-code: importers outside the program and its packages; a name looked up at run time (window[name], a route table built from strings); templates other than Vue's; public andprotectedclass members,Enummembers nothing constructs, parameters no caller passes.unreachable-code: an importedneverfunction called in both branches of anif; a function that never returns without being declarednever; narrowing that happened before the chain.unknown-event: a receiver whose class is not written down; other libraries' emitters, which have no event list. Found after filing: the receiver's class is read only where it is a parameter or a local typed with the class. A loop variable over a typed list, an element taken by index, a destructured parameter, a field ofthisand a callback's parameter get no class yet, so a misspelt name there is not reported (1 of 10 written forms in a probe of mine). Nothing is reported wrongly; the fix, through the receiver resolution the call rules already use, is in the piece stacked above this one.unmatched-event: an emitter passed around untyped or kept in a collection;once(emitter, name)fromnode:events.Created with Claude Opus 5.5 (implementation and the merge) and Claude Fable 5.2 (review and acceptance tests) in Claude Code.