require-vitest-mock-reset-policy
Require at least one enabled Vitest mock reset policy (clearMocks, resetMocks, or restoreMocks).
Rule catalog ID: R053
Targeted pattern scopeโ
vitest.config.*vitest.workspace.*vite.config.*when Vitest test options are configuredtest.clearMockstest.resetMockstest.restoreMocks
What this rule reportsโ
This rule reports test configurations that do not enable any of these policies as true:
clearMocksresetMocksrestoreMocks
Why this rule existsโ
Mock state can leak between tests when no reset/restore strategy is configured. A shared policy reduces nondeterminism and cross-suite interference.
โ Incorrectโ
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globals: true,
},
});
โ Correctโ
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
restoreMocks: true,
},
});
Behavior and migration notesโ
- this rule checks static boolean values only
- it reports once per test scope missing a mock reset policy
ESLint flat config exampleโ
import vite from "@typpi/eslint-plugin-vite";
export default [vite.configs.strict, vite.configs.vitest];
When not to use itโ
Disable this rule only if mock lifecycle is fully controlled elsewhere and this config intentionally omits those flags.