eslint-plugin-vitest
Eslint plugin for vitest
Installation
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-vitest
:
npm install eslint-plugin-vitest --save-dev
Usage
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
}
]
}
}
Recommended
To use the recommended configuration, extend it in your .eslintrc
file:
{
"extends": ["plugin:vitest/recommended"]
}
All recommend rules will be set to error by default. You can however disable some rules by setting turning them off
in your .eslintrc
file or by setting them to warn
in your .eslintrc
.
all
To use the all configuration, extend it in your .eslintrc
file:
{
"extends": ["plugin:vitest/all"]
}
Running on test files only
This plugin assumes that you're running it on tests files only by default which sometimes is not the case. If you can to run it on test files only. Your configuration will look like this:
If you're using .eslintrc
{
"extends": ["eslint:recommended"],
"overrides": [
{
"files": ["tests/**"],
"plugins": ["vitest"],
"extends": ["plugin:vitest/recommended"]
}
]
}
If you're using .eslintrc.js
import vitest from "eslint-plugin-vitest";
export default [
{
files: ["tests/**"],
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
},
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
},
];
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.
{
"extends": ["plugin:vitest/recommended"],
"settings" :{
"vitest": {
"typecheck": true,
}
}
}
Rules
💼 Configurations enabled in.
⚠️ Configurations set to warn in.
🔧 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