vitest/prefer-importing-vitest-globals Style
What it does
Enforces explicit imports from 'vitest' instead of using vitest globals.
Why is this bad?
Using vitest globals without importing them relies on implicit global configuration (globals: true in vitest config). Explicit imports make dependencies clear, improve IDE support, and ensure compatibility across different setups.
Examples
Examples of incorrect code for this rule:
js
describe("suite", () => {
it("test", () => {
expect(true).toBe(true);
});
});Examples of correct code for this rule:
js
import { describe, it, expect } from "vitest";
describe("suite", () => {
it("test", () => {
expect(true).toBe(true);
});
});How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/prefer-importing-vitest-globals": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vitest"],
rules: {
"vitest/prefer-importing-vitest-globals": "error",
},
});bash
oxlint --deny vitest/prefer-importing-vitest-globals --vitest-pluginVersion
This rule was added in v1.59.0.
