ts: the no-any rule is a check now, and the check passes on itself #2474
No reviewers
Labels
No labels
blocked-on-build
bug
device
device-request
enhancement
from-github
needs-datasheet
needs-info
needs-triage
ready-for-agent
ready-for-human
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!2474
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "build/no-any"
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?
First new TypeScript code in the repository, and the first thing it does is enforce the rule that produced it: new code is TypeScript, and
anyappears nowhere.What this adds
scripts/check-no-any.ts— scansscripts/ engine/ server/ web/ test/ types/(plus any top-level*.ts) for an explicitanyin a type position and reportsfile:line:columnfor every occurrence, exit 1 on a hit, 0 when clean, 2 on a usage error.--listprints every file it read, and an optional path argument scopes it to one directory or one file (the tests use that).test/no-any.test.ts— builds fixtures in a temp directory (os.tmpdir(), no network, no repository writes, removed in afinally) and asserts the checker can both fail and stay quiet. 28 assertions; prints28 passed, 0 failed.The spellings it catches
: anyas any<any>any[]Array<any>,Promise<any>Record<string, any><T = any>any)| anyextends anyWhat it deliberately does not catch, and why
//and/* */before anything is judged, so the documentation above — which spells out every banned form — cannot fail the file it describes.test/no-any.test.tsis strings and template literals, so the guard is blind to it by construction; if that ever broke, this PR's own self-scan would go red.${...}hands the scanner back to code, so a cast inside an interpolation is still caught. A/regex/is text too, and a quote character inside one can no longer open a string and swallow the rest of the file.unknown. A different word, and the answer to nearly every realany— the fixture narrows it withtypeofguards and passes untouched.any—row.any,{ any: 1 },interface Row { any: number }. The rules key on what surrounds the word (:,as,<,,/=inside a type argument list,|,extends,[]), never on the word alone.any— discovery is by extension.It is a lexical check, not a parser, and the header says so:
<opens a type-argument stretch when the token before it can be a type name, and the count is dropped at;,{and}. A comparison can inflate the count, which only matters if a comma inside that stretch is followed by the bare wordany.Verified
Both files also typecheck under
--strict --noUncheckedIndexedAccess --isolatedModules --verbatimModuleSyntax, with both--module nodenextand--module commonjs.The self-scan is the nicest proof here: the checker is inside its own scan path, and the test asserts that it is (
the scan reaches the checker itself,and this test file).Both files are CommonJS at run time — the repository is
"type": "commonjs", so ESM syntax cannot run (Cannot use import statement outside a module, verified). Each carries oneexport type ... = never, which makes TypeScript treat the file as a module instead of a script; without it, every.tsscript in the program shares one global scope and the first two of them collide onconst fs(TS2451, verified). The runtime strips that line because it is a type:node scripts/check-no-any.tsruns.Wiring for the TypeScript toolchain PR to absorb
Everything below touches
package.json/tsconfig.json/ the workflow, which this PR deliberately does not edit:test/*.test.tsinscripts/run-tests.js. Until that lands, the suite is run directly —node test/no-any.test.ts— which works today (Node 26.13.1 strips types natively).require,processand__dirname, so the typecheck job needs@types/nodeas a devDependency and"types": ["node"]intsconfig.json. Without them these two files do not typecheck — and no.tsfile that touchesfswill.package.json: withnpm run check:no-anyappended to thetestchain. It needs a runtime that can load.ts(22.18+ / 26), so on the Node 18 leg it has to be skipped rather than failing for the language — the test announces that case loudly (skipped: no TypeScript support in node v18...) instead of going red for the wrong reason.tsconfig.json'sincludeshould cover the same directories the checker scans.moduleDetection: "force"is not needed, because of the in-file type export.No issue to close: this is the first slice of the standing rule, not a fix for a report.