Skip to content

perf: build no-widen-then-assert scopes only when needed - #56

Open
tjsousa wants to merge 1 commit into
dmmulroy:mainfrom
tjsousa:perf/lazy-widen-then-assert-scopes
Open

tjsousa wants to merge 1 commit into
dmmulroy:mainfrom
tjsousa:perf/lazy-widen-then-assert-scopes

Conversation

@tjsousa

@tjsousa tjsousa commented Oct 15, 2026

Copy link
Copy Markdown

no-widen-then-assert reads context.sourceCode.scopeManager.scopes in its Program visitor. That forces JS-side scope analysis on every linted file, including files with no identifier as T assertion, which is the only case the rule ever needs scopes for.

This reads the scopes on the first identifier assertion in a file instead, and resets the cache in Program. Findings are unchanged.

Measured cost of enabling only this rule on top of an existing config (oxlint 1.78, Node 24, full tree, interleaved medians of 8 runs):

Codebase Before After
NestJS backend, ~9.1k TS files +807 ms +210 ms
React app, ~6.5k TS/TSX files +629 ms +130 ms

The new no-widen-then-assert-cli.test.ts covers the per-file reset. RuleTester can't see it, because each case gets a fresh rule instance, while the CLI reuses one instance across files. With the reset removed, the existing suite still passes but the CLI test fails (the second file's finding is lost to the first file's stale scopes). pnpm check passes, and pnpm sync:skill-assets mirrored the change into the skill bundle.

🤖 Generated with Claude Code

The Program visitor read sourceCode.scopeManager.scopes for every file, which forces JS-side scope analysis even for files with no identifier assertion. Read it on the first `identifier as T` in a file and reset it per file instead. Findings are unchanged; a CLI test covers the per-file reset, which RuleTester cannot see because each case gets a fresh rule instance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant