Skip to main content

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 isPreview or isSsrBuild
  • 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 : serverConfig
  • if (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) treats undefined the same as false
  • if (!isPreview) treats undefined the same as false

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 isPreview with === true when a branch should run only during preview
  • compare isSsrBuild with === true or === false when 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.

Package documentationโ€‹

Further readingโ€‹