Skip to content
← Back to rules

vitest/prefer-importing-vitest-globals Style

🛠️ An auto-fix is available for this rule.

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-plugin

Version

This rule was added in v1.59.0.

References