eslint-plugin-vitest
![ci](https://github.com/veritem/eslint-plugin-vitest/actions/workflows/ci.yml/badge.svg?branch=main)
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
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 "eslint-plugin-vitest";
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
}
]
}
}
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