Skip to main content

no-vitest-unstub-envs-false

Disallow test.unstubEnvs: false in shared Vitest config.

Rule catalog ID: R056

Targeted pattern scopeโ€‹

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

What this rule reportsโ€‹

This rule reports explicit test.unstubEnvs: false assignments in supported config files.

Why this rule existsโ€‹

Stubbed environment variables should be restored between tests to avoid state leakage across suites. Disabling env unstubbing can create order-dependent behavior.

โŒ Incorrectโ€‹

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
unstubEnvs: false,
},
});

โœ… Correctโ€‹

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
unstubEnvs: true,
},
});

Behavior and migration notesโ€‹

  • this rule checks static boolean assignments only
  • it targets committed config files, not arbitrary source modules

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 env stubbing lifecycle is handled externally and this flag is intentionally false.

Package documentationโ€‹

Further readingโ€‹