Skip to main content

config-require-define-config

Require Vite config files to export defineConfig(...), mergeConfig(...), or defineWorkspace(...) instead of raw objects.

Rule catalog ID: R001

Targeted pattern scopeโ€‹

  • vite.config.*
  • vitest.config.*
  • vitest.workspace.*

What this rule reportsโ€‹

This rule reports default exports in recognized config files when they are raw objects, arrays, or other expressions instead of the helper APIs Vite and Vitest document for config authoring.

Why this rule existsโ€‹

The helper wrappers make intent explicit and keep config authoring aligned with the documented APIs.

That matters for:

  • editor inference
  • ecosystem examples and copy-pasteability
  • composing configs with mergeConfig(...)
  • using the dedicated workspace helper in vitest.workspace.*

โŒ Incorrectโ€‹

export default {
resolve: {
alias: {
"@": "/src",
},
},
};
export default [{
test: {
name: "unit",
},
}];

โœ… Correctโ€‹

import { defineConfig } from "vite";

export default defineConfig({
resolve: {
alias: {
"@": "/src",
},
},
});
import { defineWorkspace } from "vitest/config";

export default defineWorkspace([
{
test: {
name: "unit",
},
},
]);

Behavior and migration notesโ€‹

  • vite.config.* and vitest.config.* accept either defineConfig(...) or mergeConfig(...).
  • vitest.workspace.* should use defineWorkspace(...).
  • Exporting an identifier is also valid when that identifier is initialized from the correct helper call, such as const config = defineConfig({...}); export default config;.
  • This rule does not rewrite imports automatically because the correct helper depends on the file type.

ESLint flat config exampleโ€‹

import vite from "@typpi/eslint-plugin-vite";

export default [vite.configs.configs];

When not to use itโ€‹

Disable this rule only if your repository intentionally uses a non-standard config-export pattern and your team documents that deviation.

Package documentationโ€‹

Further readingโ€‹