oxc-project/oxc · error · OxcDiagnostic

Do not use Vitest global functions

Error message

Do not use Vitest global functions

What it means

Emitted by the vitest/prefer-importing-vitest-globals rule when vitest global functions (`describe`, `it`, `expect`, ...) are used in a file that has not imported them from the `'vitest'` package. It fires because the project runs vitest without `globals: true`, so relying on auto-injected globals will fail at runtime.

Source

Thrown at crates/oxc_linter/src/rules/vitest/prefer_importing_vitest_globals.rs:25

use oxc_macros::declare_oxc_lint;
use oxc_semantic::AstNode;
use oxc_span::{GetSpan, Span};
use oxc_str::CompactStr;
use rustc_hash::FxHashSet;

use crate::{
    context::LintContext,
    fixer::{RuleFix, RuleFixer},
    module_record::ImportImportName,
    rule::Rule,
    utils::is_vitest_import_source,
};

fn prefer_importing_vitest_globals_diagnostic(
    spans: &[Span],
    globals_founds: &str,
) -> OxcDiagnostic {
    OxcDiagnostic::warn("Do not use Vitest global functions")
        .with_help(format!(
            "Import global functions `{globals_founds}` from `vitest` package instead of using globals."
        ))
        .with_labels(spans.iter().map(|span| span.label("Add this global vitest import")))
}

// Vitest provides a `jest` global for migration compatibility

/// Vitest globals that should be imported explicitly.
const VITEST_GLOBALS: [CompactStr; 17] = [
    CompactStr::new_const("afterAll"),
    CompactStr::new_const("afterEach"),
    CompactStr::new_const("beforeAll"),
    CompactStr::new_const("beforeEach"),
    CompactStr::new_const("bench"),
    CompactStr::new_const("describe"),
    CompactStr::new_const("expect"),
    CompactStr::new_const("expectTypeOf"),

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add the missing imports, e.g. `import { describe, it, expect } from 'vitest';` (a fix is provided)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/vitest/prefer_importing_vitest_globals.rs:25 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/da6a95a60b33d1bd. Report an issue: GitHub.