Skip to main content

require-vitest-coverage-thresholds-when-enabled

Require explicit non-empty test.coverage.thresholds when coverage is enabled.

Rule catalog ID: R045

Targeted pattern scopeโ€‹

  • vitest.config.*
  • vitest.workspace.*
  • vite.config.* when Vitest coverage is configured
  • test.coverage.enabled: true

What this rule reportsโ€‹

This rule reports enabled coverage blocks that omit thresholds or provide empty thresholds objects.

Why this rule existsโ€‹

Coverage without thresholds measures but does not enforce quality gates. Explicit thresholds make CI quality expectations clear and enforceable.

โŒ Incorrectโ€‹

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
coverage: {
enabled: true,
thresholds: {},
},
},
});

โœ… Correctโ€‹

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
coverage: {
enabled: true,
thresholds: {
lines: 80,
functions: 80,
branches: 75,
statements: 80,
},
},
},
});

Behavior and migration notesโ€‹

  • this rule requires a non-empty static thresholds object
  • threshold values themselves are not range-validated by this 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 coverage quality gates are enforced entirely outside Vitest config.

Package documentationโ€‹

Further readingโ€‹