eslint-plugin-vitest
raw JSON → 0.5.4 verified Sat Apr 25 auth: no javascript
ESLint plugin for Vitest, providing test-specific linting rules. The latest stable version is 1.6.16, released on npm with type definitions included. This plugin helps enforce best practices in Vitest test suites, including rules for consistent naming, focused tests, and proper assertions. It supports both ESLint v8 (flat config and legacy) and v9. Key differentiators include type-testing support, a comprehensive set of rules (e.g., no-focused-tests, valid-expect), and compatibility with Vitest's chaining API. The plugin is actively maintained, with frequent releases addressing bugs and adding features. It requires ESLint >=8.57.0 and Vitest as peer dependencies.
Common errors
error Error: Failed to load plugin 'vitest' declared in '.eslintrc.json' ↓
cause Plugin not installed or ESLint cannot find it
fix
Run 'npm install --save-dev eslint-plugin-vitest' and ensure node_modules includes it.
error Definition for rule 'vitest/no-focused-tests' was not found ↓
cause Using a rule that doesn't exist or incorrect plugin version
fix
Check rule name spelling; verify plugin version supports the rule (v1.0+ includes core rules).
error TypeError: vitest.configs is not iterable ↓
cause Incorrect import or usage in flat config; configs is an object, not array
fix
Use: export default [ ...vitest.configs.recommended ] or spread properly.
error ESLint couldn't determine the plugin for rule 'vitest/expect-expect' ↓
cause Plugin not specified in 'plugins' array or object
fix
Add 'vitest' in the flat config's plugins object: { plugins: { vitest } }
Warnings
breaking ESLint v9 flat config requires different plugin structure than legacy .eslintrc ↓
fix Use import vitest from 'eslint-plugin-vitest' and spread vitest.configs.recommended in flat config.
deprecated The 'vitest/no-alias-methods' rule may have reversed alias direction in v1.6.12 ↓
fix Check your usage: toThrow/toThrowError alias direction was fixed. Update code if needed.
gotcha TypeScript type definitions are shipped but need '@typescript-eslint' for full integration ↓
fix Install and configure @typescript-eslint/parser and plugin to resolve type-aware rules.
breaking Plugin requires ESLint >=8.57.0; older versions may not work ↓
fix Upgrade ESLint to v8.57.0+ or use v9+ for flat config.
deprecated The 'all' config sets warn level; be aware if using spread ↓
fix Use 'recommended' instead of 'all' to avoid too many warnings.
Install
npm install eslint-plugin-vitest yarn add eslint-plugin-vitest pnpm add eslint-plugin-vitest Imports
- plugin (default) wrong
const vitest = require('eslint-plugin-vitest')correctimport vitest from 'eslint-plugin-vitest' - vitest.configs.recommended wrong
import { recommended } from 'eslint-plugin-vitest'correctimport vitest from 'eslint-plugin-vitest'; export default [...vitest.configs.recommended] - vitest.environments.env.globals wrong
import { environments } from 'eslint-plugin-vitest'correctimport vitest from 'eslint-plugin-vitest'; globals: { ...vitest.environments.env.globals } - Rule: vitest/no-focused-tests wrong
rules: { no-focused-tests: 'error' }correctrules: { 'vitest/no-focused-tests': 'error' }
Quickstart
// Install: npm install --save-dev eslint eslint-plugin-vitest
// eslint.config.js (ESLint v9 flat config)
import vitest from 'eslint-plugin-vitest';
export default [
{
files: ['**/*.test.js', '**/*.test.ts'],
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
'vitest/no-focused-tests': 'error',
},
settings: {
vitest: {
typecheck: true, // enable if using Vitest type-testing
},
},
},
];