vitest/prefer-importing-vitest-globals

January 2, 2026 ยท View on GitHub

๐Ÿ“ Enforce importing Vitest globals.

โš ๏ธ This rule warns in the ๐ŸŒ all config.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

โš ๏ธ This rule warns in the ๐ŸŒ all config.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

Rule Details

This rule enforces importing Vitest globals.

Examples of incorrect code for this rule:

test('foo', () => {
  expect(1).toBe(1)
})

Examples of correct code for this rule:

import { test, expect } from 'vitest'

test('foo', () => {
  expect(1).toBe(1)
})
const { test, expect } = require('vitest')

test('foo', () => {
  expect(1).toBe(1)
})