Repository navigation
Conversation
…hange what the file does
`--fix` deleted `const { vi: spy, test, expect } = require("vitest")` and
left `spy` undeclared. The fix is oxlint's. It goes by the key of a
property, or by the local name of an import, and looks at nothing else.
Both report sites now use `Report::fix_where_safe`. `--fix` applies the fix
where the global of the same name is what each removed name was, and where
the rest of the file stays what it is. `--fix-dangerously` applies oxlint's
text to the other statements. The reports do not change.
`Fixer::remove_statement` is new. It removes a whole statement, unless that
loses a comment, leaves a `// @ts-ignore` to the next statement, joins the
statements around it, or takes the body of an `if` or a loop.
|
No actionable comments were generated in the recent review. WalkthroughThe Vitest globals rule adds safety checks before fixing imports and ChangesVitest global import fixes
Suggested reviewers: Merge Risk:
|
|
Updated 12:32 PM PT - Nov 13th, 2026
✅ @robobun, your commit 850afd9015c06336f02c6b2af886e27bf18c0371 passed in 🧪 To try this PR locally: bunx bun-pr 48780That installs a local version of the PR into your bun-48780 --bun |
|
Status
|
… are true for every runner
`--fix` now leaves every import from `@effect/vitest` to
`--fix-dangerously`, and a `require()` call with type arguments. The
rule has no list of the names that the package declares itself.
Two holds are gone, because they are only true for `bun test`:
- the last `import` of a file that mentions `require`, `module` or
`exports`
- `assert` and `chai`, which Vitest has as globals
The check for a TypeScript file that would become a script counts
only the imports that the fix removes whole. It does not count an
export of no names, which `@typescript-eslint/no-useless-empty-export`
can remove in the same pass.
A name that the file exports with `export { name }` gets no fix: the
text would leave the export without its name.
`Fixer::remove_statement` accepts a statement in a `namespace` block
and ignores a directive comment in the header of the file. It does not
remove a statement above a string statement, which could become a
directive, or between `a++` and a line that starts with `(`, which Bun
and esbuild take for a call.
…ypeScript file with `import.meta`
TypeScript takes a file with `import.meta` or `import a = require("a")`
for a module in every `moduleDetection` mode. The removal of the last
`import` of such a file does not make it a script, so `--fix` applies
it.
A name that the file exports with `export { name }` gets no fix also
where a nested pattern of a `require()` binds it.
|
Changes for the second round of review comments, in 850afd9:
The test file has 92 tests now. 49 of them fail on main's lint code. |
|
No code change for the third round of review comments. I checked both with tsc:
The PR notes name both cases under "Not in this PR". |
Problem
bun lint --fixwithvitest/no-importing-vitest-globalsdeletesconst { vi: spy, test, expect } = require("vitest"). The file still usesspy:ReferenceError: spy is not defined..fix(src/lint/jest/rules/vitest_no_importing_vitest_globals.rs:77,:129): it goes by the key or the local name. A probe found it.Fix
Report::fix_where_safe:--fixapplies the fix only where the same-named global is what each removed name was,--fix-dangerouslythe rest. Reports stay.@effect/vitestnames, a TypeScript file that would become a script. Each is wrong for every runner.Fixer::remove_statementrefuses a removal that loses a comment, joins two statements or makes a directive.test/cli/lint/no-importing-vitest-globals.test.ts(runsbun teston 91 files around each flag, and 49 of 92 tests fail on main),conformance,rule-docs. Self-reviewed: 116 concerns raised, 95 addressed.Background
fix_where_safe(is_safe, fix):--fixskips the fix ifis_safeis false (docs/lint/index.mdx:65).bun testjudge avitest/*fix (bun lint: hold back fixes that change whatbun testdoes with module mocks onjestorvi#48674 (comment))?src/lint/jest/jest.rs:8: these rules see what oxlint sees. This PR holds under both answers.testfromspy).Downsides
--fixskips 853 of 5,573 fixes in 16 code bases (715 for@effect/vitest) and 2 of 41 recorded oxlint cases..text+10,240 bytes, and 3 more instructions per file that importsvitest.bun teststill breaks where it differs from Vitest: no globalassert, and withoutglobals = "vitest"the import selects the file's globals.Notes
Origin and reach
bun lint --fixagainstbun testfound thevi: spycase. The tracker has no issue for this rule, and no stable release hasbun lint. The contract isdocs/lint/index.mdx:65(bun check: 1.4x to 7.8x faster on large projects. Fixes forbun check,bun lintandbun fmt#45800):--fixapplies no fix that is known to change what a program does.stylecategory turns it on, together with its opposite (vitest/prefer-importing-vitest-globals).require("vitest")throws under Vitest itself. The 16 code bases have 0require()statements that the rule reports, and 1 rename.--fix. Its behavior is not reported upstream.bun testdoes with module mocks onjestorvi#48674 changes the same two sites for module mocks. The PR that lands second joins its predicate with&&.Reach of each guard (5,573 reports in 16 code bases)
@effect/vitest// @ts-ignoreWhat
--fixleaves to--fix-dangerously{ vi: spy },{ vi: { fn } },{ [key]: spy },{ vi = fallback },import { inject as vi },import { "vi" as spy }@effect/vitestbeforeAll,beforeEachanditin 4.1.4): itsithasit.effect()require()require()that is aletor avar, or inside a function or anamespaceletcan be assigned, and in a function the name can be an outer variable'srequire()declaration with a type annotation or type argumentsimportof a TypeScript file whose top level has more than expression statements, or anawaittsconfig.json, which the rule does not read. A file withimport.metaorimport a = require("a")is a module in every case. Anexport {}does not count: another rule can remove it in the same passWhat no flag fixes: a statement with a comment that the fix would lose, a statement below
// @ts-ignoreor// prettier-ignore, a statement whose removal joins the next line to the one before (also aftera++, which Bun and esbuild join to a(), a statement above a string statement (it could become a directive), a name that the file exports withexport { name }, an import next to a default import, arequire()that is the body of anif, an exportedrequire()with no name that stays. oxlint's text is wrong for each of these.Not in this PR
bun test. They wait for the answer to the question above, and they need one shared check for the three rules that add or remove this import.assertandchaiare globals in Vitest.bun testhas neither, with any setting (docs/test/configuration.mdx:120). 67 of the 5,573 reports importassert.globals = "vitest", the import selects the file's globals (docs/test/configuration.mdx:107). A file that loses it has nosuite,vitest,assertTypeoronTestFailed. The check needs[test].globals.import,exportandrequire(src/js_parser/parse/parse_entry.rs:1939). A file that loses its lastimportor its onlyrequire()can change. The first commit held back a lastimportin a file that mentionsrequire,moduleorexports. A review found that check wrong in both directions, so it is gone.stylecategory, each run of--fixundoes the run before. main and oxlint do the same.export {}is handled.jest/prefer-importing-jest-globals(src/lint/jest/rules/jest_prefer_importing_jest_globals.rs:93),vitest/consistent-vitest-vi(vitest_consistent_vitest_vi.rs:53,:73),react/destructuring-assignment(react_destructuring_assignment.rs:338).Ctx::risky_fix(src/lint/jest/jest.rs:53) keeps a plain fix for six rules whose fix can fail a test. That is a separate decision. This rule's fix leaves a name undeclared or bound to another value.Fixer::remove_statementyet. Three can take it as is:no_useless_empty_export.rs:51,unicorn_require_module_specifiers.rs:74,unicorn_prefer_class_fields.rs:92. Each changes what another rule fixes, so each needs its own test rows./** */.checkJs,// @ts-check) can become a script as well. The check is for TypeScript files..mtsor.ctsfile stays held back like a.tsfile. WithmoduleDetection: "legacy"it is a script without animport(tsc 5.0.4 to 6.0.2: TS2451 for two such files).isolatedModules. The check does not hold a file back for that: 4.9.5 reports it, 5.0.4 and later do not.no-undefreportsassertType,vitest,onTestFailedandonTestFinishedin a JavaScript file. It does not know these globals. main does the same.a++and a(on a later line for a call (src/js_parser/parse/parse_suffix.rs:509). Node does not.(, with an oxlint config: the second one waits for the next run.Measurements (linux x64, main 9ea3c69 against this diff on that commit)
@effect/vitest.bun lint --run-eslint-tests --suite=oxlintprints the text ofexpected-oxlint.txt, which now has "434 cases have a fix that --fix holds back" (main: 432). Theupstreamandmoresuites have no new failure.vitest, no config, the rule set with--rule. Both builds make the same 5,573 reports. 4,720 keep a plain fix, 795 are held back, 58 get no fix. The text and range of every remaining fix equal main's.--threads=1): 0 for a file that does not mentionvitest, and 0 where fixes are not read (--format unix, oxlint's JSON). 1 per report with--fix-dry-run.(,[, a backtick,/,+,-or<.--threads=1): equal to main for files that are not reported, for fixes that--fixapplies, and where fixes are not read. A held-back report: 85,931 against 82,931 where JSON prints the fix, and 74,189 against 120,230 with--fix-dry-run, which applies nothing. An import before a line that starts with(: 5 more per file.llvm-size -A):.text122,621,673 to 122,631,913 (+10,240),.rodataunchanged, file +12,288. The rule's symbols and its helpers: 20,013 bytes against 10,640.Fixer::remove_statement: 2,874 bytes.vitestand are not reported (perf_event_open, median of 7 interleaved runs each,--threads=1): 285,766,038 against 285,736,079, which is +29,959 or 3 per file. Four of the seven runs of each binary are within 300.perfandvalgrindare not installed here.Tests
--fixand with--fix-dangerously, with no config and next to an.oxlintrc.json.bun testruns them as written and after each flag, withglobals = "vitest".bun testhas as a global of Vitest, as animportand as arequire(). One test asserts thatbun testexits with 0 after--fix.mock-hoisting.test.tsin bun lint: hold back fixes that change whatbun testdoes with module mocks onjestorvi#48674. The PR that lands second moves both tables onto one module.test/cli/lint/defaults.test.ts, because that table does not runbun test.Review history
assert,chaiand a lastimportnext torequire, and it listed three names of@effect/vitest. The second commit removes the first two holds (see "Not in this PR") and holds back every name of that package.fixkey on the example markers of the docs pages: a change to the docs test, for its own PR.Fixer::remove_statement: each changes another rule's fixes. They are named above.eslint-disable-next-line, above a string with a statement before it, or for@ts-ignoreon the last line of a block comment:is_next_line_directiveis main's and has other callers, and the refusals are in the safe direction.thisin a top-level arrow function of a would-be script, and forvi.mock()hoisting underbun test(bun lint: hold back fixes that change whatbun testdoes with module mocks onjestorvi#48674 has that one).// @ts-nocheck.