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
Make sure you're running eslint v9.0.0
or heigher eslint.config.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.
import vitest from "eslint-plugin-vitest";
export default [
{
files: ["tests/**"],
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
},
settings: {
vitest: {
typecheck: true
}
},
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
},
]
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