require-vitest-environment-match-globs
Require explicit non-empty test.environmentMatchGlobs when multiple static test.environment values are used in one config file.
Rule catalog ID: R058
Targeted pattern scopeโ
vitest.config.*vitest.workspace.*vite.config.*when Vitest test options are configuredtest.environmenttest.environmentMatchGlobs
What this rule reportsโ
This rule reports files that define multiple static test.environment values without also configuring a non-empty test.environmentMatchGlobs.
Why this rule existsโ
When multiple environments are used, explicit environment-to-file routing helps keep execution deterministic and easier to reason about. Implicit routing can become ambiguous in larger projects.
โ Incorrectโ
import { defineConfig, defineProject } from "vitest/config";
export default defineConfig({
test: {
projects: [
defineProject({ test: { environment: "node" } }),
defineProject({ test: { environment: "jsdom" } }),
],
},
});
โ Correctโ
import { defineConfig, defineProject } from "vitest/config";
export default defineConfig({
test: {
projects: [
defineProject({ test: { environment: "node" } }),
defineProject({ test: { environment: "jsdom" } }),
],
environmentMatchGlobs: [["**/*.dom.test.ts", "jsdom"]],
},
});
Behavior and migration notesโ
- this rule checks static environment strings only
- non-empty
environmentMatchGlobsarrays satisfy the rule
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 environment routing is guaranteed by an external layer and intentionally not expressed in Vitest config.