Skip to main content

no-vitest-env-leakage-combo

Disallow risky Vitest state-leakage combos that mix globals: true, isolate: false, and disabled unstub flags.

Rule catalog ID: R057

Targeted pattern scopeโ€‹

  • vitest.config.*
  • vitest.workspace.*
  • vite.config.* when Vitest test options are configured
  • test.globals
  • test.isolate
  • test.unstubGlobals
  • test.unstubEnvs

What this rule reportsโ€‹

This rule reports test scopes that statically configure:

  • test.globals: true
  • test.isolate: false
  • and at least one of:
    • test.unstubGlobals: false
    • test.unstubEnvs: false

Why this rule existsโ€‹

That combination makes global/environment state carry-over more likely across tests. In shared config, this often increases flakiness and order dependence.

โŒ Incorrectโ€‹

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
isolate: false,
unstubGlobals: false,
},
});

โœ… Correctโ€‹

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
isolate: true,
unstubGlobals: false,
},
});

Behavior and migration notesโ€‹

  • this rule checks static boolean assignments only
  • it reports once per affected test scope

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 your harness intentionally relies on cross-test global/env state behavior.

Package documentationโ€‹

Further readingโ€‹