vitest/prefer-import-in-mock Style
What it does
This rule enforces using a dynamic import() in vi.mock(), which improves type information and IntelliSense for the mocked module.
Why is this bad?
A lack of type information and IntelliSense increase the risk of mismatches between the real module and it's mock.
Examples
Examples of incorrect code for this rule:
js
vi.mock("./path/to/module");Examples of correct code for this rule:
js
vi.mock(import("./path/to/module"));Configuration
This rule accepts a configuration object with the following properties:
fixable
type: boolean
How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/prefer-import-in-mock": "error"
}
}bash
oxlint --deny vitest/prefer-import-in-mock --vitest-plugin