{"record":{"id":"2c87bfda486395e7","repo":"oxc-project/oxc","slug":"do-not-import-require-global-functions-from-v","errorCode":null,"errorMessage":"Do not `import`/`require` global functions from 'vitest'.","messagePattern":"Do not `import`/`require` global functions from 'vitest'\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/no_importing_vitest_globals.rs","lineNumber":19,"sourceCode":"use itertools::Itertools;\nuse oxc_ast::{\n    AstKind,\n    ast::{\n        Argument, BindingPattern, Expression, ImportDeclarationSpecifier, ImportOrExportKind,\n        VariableDeclarationKind, VariableDeclarator,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::AstNode;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{context::LintContext, rule::Rule, utils::is_vitest_import_source};\n\nfn no_importing_vitest_globals_diagnostic(spans: &[Span]) -> OxcDiagnostic {\n    let help = format!(\"You can import anything except `{}`.\", VITEST_GLOBALS.join(\", \"));\n\n    OxcDiagnostic::warn(\"Do not `import`/`require` global functions from 'vitest'.\")\n        .with_help(help)\n        .with_labels(spans.iter().map(|span| span.label(\"Remove this global vitest import\")))\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoImportingVitestGlobals;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// The rule disallows importing any Vitest global functions.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// If a project is [configured to provide Vitest functions as globals](https://vitest.dev/config/globals.html),\n    /// this rule can be used to ensure that the globals are never imported\n    /// via `import` or `require`.\n    ///","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/no_importing_vitest_globals.rs#L1-L37","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/no_importing_vitest_globals.rs:19 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the named imports and rely on the vitest globals","Or disable vitest `globals` in config and keep explicit imports, but apply consistently"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}