{"record":{"id":"514ead1d0a012d15","repo":"oxc-project/oxc","slug":"mocked-modules-must-be-dynamic-imported","errorCode":null,"errorMessage":"Mocked modules must be dynamic imported.","messagePattern":"Mocked modules must be dynamic imported\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/prefer_import_in_mock.rs","lineNumber":19,"sourceCode":"use oxc_ast::{AstKind, ast::Argument};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::{PossibleJestNode, parse_general_jest_fn_call},\n};\n\nfn prefer_import_in_mock_diagnostic(span: Span, path: &str) -> OxcDiagnostic {\n    let help = format!(\n        \"Dynamic import improves the type information and IntelliSense. Substitute `{path}` with `import('{path}')`\"\n    );\n\n    OxcDiagnostic::warn(\"Mocked modules must be dynamic imported.\").with_help(help).with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferImportInMock(Box<PreferImportInMockConfig>);\n\nimpl std::ops::Deref for PreferImportInMock {\n    type Target = PreferImportInMockConfig;\n\n    fn deref(&self) -> &Self::Target {\n        &self.0\n    }\n}\n\n#[derive(Debug, Clone, PartialEq, Eq, Deserialize, JsonSchema)]\n#[serde(deny_unknown_fields)]\npub struct PreferImportInMockConfig {\n    /// Whether the rule should generate fixes or not.\n    fixable: bool,","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/prefer_import_in_mock.rs#L1-L37","documentation":"Emitted by the vitest/prefer-import-in-mock rule at a `vi.mock()` call whose module path is given as a plain string instead of a dynamic `import()` expression. It fires because `vi.mock(import('./path'), ...)` gives vitest better type information and IDE IntelliSense than the string form.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/prefer_import_in_mock.rs:19 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `vi.mock('./path', ...)` with `vi.mock(import('./path'), ...)`"],"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"}