{"record":{"id":"fdf1e745eb99fc89","repo":"oxc-project/oxc","slug":"import-the-following-jest-functions-from-jest-gl","errorCode":null,"errorMessage":"Import the following Jest functions from `@jest/globals`: {globals}","messagePattern":"Import the following Jest functions from `@jest/globals`: (.+?)","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jest/prefer_importing_jest_globals.rs","lineNumber":25,"sourceCode":"use oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::FxHashSet;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    module_record::ImportImportName,\n    rule::{DefaultRuleConfig, Rule},\n    utils::{\n        JestFnKind, JestGeneralFnKind, ParsedJestFnCallNew, collect_possible_jest_call_node,\n        parse_jest_fn_call,\n    },\n};\n\nfn prefer_importing_jest_globals_diagnostic(span: Span, globals: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Import the following Jest functions from `@jest/globals`: {globals}\"\n    ))\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct PreferImportingJestGlobals(Box<PreferImportingJestGlobalsConfig>);\n\nimpl std::ops::Deref for PreferImportingJestGlobals {\n    type Target = PreferImportingJestGlobalsConfig;\n    fn deref(&self) -> &Self::Target {\n        &self.0\n    }\n}\n\n#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct PreferImportingJestGlobalsConfig {","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jest/prefer_importing_jest_globals.rs#L7-L43","documentation":"This is oxlint's 'jest/prefer-importing-jest-globals' diagnostic. It collects all Jest globals used in a file (describe, it, expect, jest, beforeEach, ...) that are not already imported and reports them in one message listing the missing names, with a fixer that adds the import from @jest/globals. Importing explicitly makes the dependency on Jest visible and supports environments where globals are disabled (injectGlobals: false).","triggerScenarios":"Enable the rule and lint a file that calls describe/it/expect (recognized via parse_jest_fn_call) without a matching named import from @jest/globals for every used global. The diagnostic message lists the specific globals, e.g. \"Import the following Jest functions from `@jest/globals`: describe, it, expect\".","commonSituations":"Projects migrating to explicit imports (or enabling injectGlobals: false in jest.config.js) hit this across every existing spec file. Also common when moving from Create React App defaults, where globals are injected, to ESM-style setups where globals resolve ambiguously or collide with user-defined names.","solutions":["Apply the autofix (or manually add): import { describe, it, expect } from '@jest/globals'; at the top of the file.","Keep the import list in sync when adding new globals (jest, beforeEach, beforeAll, afterEach, afterAll).","If your project deliberately relies on injected globals, disable the rule in .oxlintrc.json.","Combine with jest.config.js injectGlobals settings so runtime and lint expectations match."],"exampleFix":"// before\ndescribe('math', () => {\n  it('adds', () => {\n    expect(1 + 1).toBe(2);\n  });\n});\n\n// after\nimport { describe, it, expect } from '@jest/globals';\n\ndescribe('math', () => {\n  it('adds', () => {\n    expect(1 + 1).toBe(2);\n  });\n});","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write new spec files with the @jest/globals import from the start.","Run oxlint --fix once when adopting the rule to add imports across the suite.","If you disable injected globals in jest.config.js, keep this lint rule on so missing imports surface at lint time, not runtime."],"tags":["lint","jest","testing","imports","globals","autofix","oxlint"],"backgroundTag":"jest-globals-import","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"}