eslint-plugin-vitest
ESLint plugin for Vitest
Installation
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install @vitest/eslint-plugin
npm install @vitest/eslint-plugin --save-dev
Usage
Make sure you're running ESLint v9.0.0
or higher for the latest version of this plugin to work. The following example is how your eslint.config.js
should be setup for this plugin to work for you.
import vitest from "@vitest/eslint-plugin";
export default [
{
files: ["tests/**"],
plugins: {
vitest
},
rules: {
...vitest.configs.recommended.rules,
"vitest/max-nested-describe": ["error", { "max": 3 }]
},
},
];
If you're not using the latest version of ESLint (version v8.57.0
or lower) you can setup this plugin using the following configuration
Add vitest
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": ["@vitest"]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"vitest/max-nested-describe": [
"error",
{
"max": 3
}
]
}
}
If you're using old ESLint configuration, make sure to use legacy key like the following
{
"extends": ["plugin:@vitest/legacy-recommended"]
}
Enabling with type-testing
Vitest ships with an optional type-testing feature, which is disabled by default.
If you're using this feature, you should also enabled typecheck
in the settings for this plugin. This ensures that rules like expect-expect account for type-related assertions in tests.
import vitest from "@vitest/eslint-plugin";
export default [
{
files: ["tests/**"],
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
},
settings: {
vitest: {
typecheck: true
}
},
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
},
]
Shareable configurations
Recommended
This plugin exports a recommended configuration that enforces good testing practices.
To enable this configuration with eslint.config.js
, use vitest.configs.recommended
:
import vitest from "@vitest/eslint-plugin";
export default [
{
files: ["tests/**"],
...vitest.configs.recommended,
}
]
All
If you want to enable all rules instead of only some you can do so by adding the all configuration to your eslint.config.js
config file:
import vitest from "@vitest/eslint-plugin";
export default [
{
files: ["tests/**"],
...vitest.configs.all,
}
]
Rules
💼 Configurations enabled in.
⚠️ Configurations set to warn in.
🌐 Set in the all
configuration.
✅ Set in the recommended
configuration.
🔧 Automatically fixable by the --fix
CLI option.
💡 Manually fixable by editor suggestions.
❌ Deprecated.
Credits
- eslint-plugin-jest
Most of the rules in this plugin are essentially ports of Jest plugin rules with minor modifications
Licence
MIT Licence © 2022 - present veritem and contributors