oxc-project/oxc · error · OxcDiagnostic

Do not `import`/`require` global functions from 'vitest'.

Error message

Do not `import`/`require` global functions from 'vitest'.

What it means

Emitted by the vitest/no-importing-vitest-globals rule when a named import/require pulls one of vitest's global API functions (`describe`, `it`, `test`, `expect`, `vi`, etc.) from the `'vitest'` module. When the project enables vitest globals, importing them from the package is redundant and inconsistent with the globals mode.

Source

Thrown at crates/oxc_linter/src/rules/vitest/no_importing_vitest_globals.rs:19

use itertools::Itertools;
use oxc_ast::{
    AstKind,
    ast::{
        Argument, BindingPattern, Expression, ImportDeclarationSpecifier, ImportOrExportKind,
        VariableDeclarationKind, VariableDeclarator,
    },
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::AstNode;
use oxc_span::{GetSpan, Span};

use crate::{context::LintContext, rule::Rule, utils::is_vitest_import_source};

fn no_importing_vitest_globals_diagnostic(spans: &[Span]) -> OxcDiagnostic {
    let help = format!("You can import anything except `{}`.", VITEST_GLOBALS.join(", "));

    OxcDiagnostic::warn("Do not `import`/`require` global functions from 'vitest'.")
        .with_help(help)
        .with_labels(spans.iter().map(|span| span.label("Remove this global vitest import")))
}

#[derive(Debug, Default, Clone)]
pub struct NoImportingVitestGlobals;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// The rule disallows importing any Vitest global functions.
    ///
    /// ### Why is this bad?
    ///
    /// If a project is [configured to provide Vitest functions as globals](https://vitest.dev/config/globals.html),
    /// this rule can be used to ensure that the globals are never imported
    /// via `import` or `require`.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the named imports and rely on the vitest globals
  2. Or disable vitest `globals` in config and keep explicit imports, but apply consistently
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/vitest/no_importing_vitest_globals.rs:19 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/2c87bfda486395e7. Report an issue: GitHub.