{"record":{"id":"da6a95a60b33d1bd","repo":"oxc-project/oxc","slug":"do-not-use-vitest-global-functions","errorCode":null,"errorMessage":"Do not use Vitest global functions","messagePattern":"Do not use Vitest global functions","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/prefer_importing_vitest_globals.rs","lineNumber":25,"sourceCode":"use oxc_macros::declare_oxc_lint;\nuse oxc_semantic::AstNode;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\nuse rustc_hash::FxHashSet;\n\nuse crate::{\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    module_record::ImportImportName,\n    rule::Rule,\n    utils::is_vitest_import_source,\n};\n\nfn prefer_importing_vitest_globals_diagnostic(\n    spans: &[Span],\n    globals_founds: &str,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not use Vitest global functions\")\n        .with_help(format!(\n            \"Import global functions `{globals_founds}` from `vitest` package instead of using globals.\"\n        ))\n        .with_labels(spans.iter().map(|span| span.label(\"Add this global vitest import\")))\n}\n\n// Vitest provides a `jest` global for migration compatibility\n\n/// Vitest globals that should be imported explicitly.\nconst VITEST_GLOBALS: [CompactStr; 17] = [\n    CompactStr::new_const(\"afterAll\"),\n    CompactStr::new_const(\"afterEach\"),\n    CompactStr::new_const(\"beforeAll\"),\n    CompactStr::new_const(\"beforeEach\"),\n    CompactStr::new_const(\"bench\"),\n    CompactStr::new_const(\"describe\"),\n    CompactStr::new_const(\"expect\"),\n    CompactStr::new_const(\"expectTypeOf\"),","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/prefer_importing_vitest_globals.rs#L7-L43","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/prefer_importing_vitest_globals.rs:25 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add the missing imports, e.g. `import { describe, it, expect } from 'vitest';` (a fix is provided)"],"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"}