no-implicit-config-flags
Disallow implicit truthy or falsy checks for Vite config callback flags such as isPreview and isSsrBuild.
Rule catalog ID: R013
Targeted pattern scopeโ
vite.config.*- conditional config factory functions that receive
isPrevieworisSsrBuild if, ternary, loop, and similar conditional tests inside the config callback
What this rule reportsโ
This rule reports config callback conditions such as:
if (isPreview) { ... }!isSsrBuild ? clientConfig : serverConfigif (process.env.CI === "true" || isPreview) { ... }
Why this rule existsโ
Vite's config callback receives isPreview and isSsrBuild as optional flags.
The Vite docs note that some tools loading a config can pass undefined for these values instead of a strict boolean.
That makes generic truthy or falsy checks easy to misread:
if (isPreview)treatsundefinedthe same asfalseif (!isPreview)treatsundefinedthe same asfalse
An explicit comparison communicates intent better and prevents undefined from silently joining one branch.
โ Incorrectโ
import { defineConfig } from "vite";
export default defineConfig(({ isPreview, isSsrBuild }) => {
if (isPreview) {
return {
preview: {
open: true,
},
};
}
return !isSsrBuild
? {
build: {
sourcemap: true,
},
}
: {
build: {
ssr: "src/entry-server.ts",
},
};
});
โ Correctโ
import { defineConfig } from "vite";
export default defineConfig(({ isPreview, isSsrBuild }) => {
if (isPreview === true) {
return {
preview: {
open: true,
},
};
}
return isSsrBuild === false
? {
build: {
sourcemap: true,
},
}
: {
build: {
ssr: "src/entry-server.ts",
},
};
});
Behavior and migration notesโ
- compare
isPreviewwith=== truewhen a branch should run only during preview - compare
isSsrBuildwith=== trueor=== falsewhen SSR and client branches must stay distinct - this rule is intentionally scoped to Vite config callback flags, not arbitrary boolean values in the file
ESLint flat config exampleโ
import vite from "@typpi/eslint-plugin-vite";
export default [vite.configs.configs, vite.configs.strict];
When not to use itโ
Disable this rule only if your team intentionally treats undefined the same as one branch and prefers that looser conditional style.