Package Exports
- eslint-plugin-vitest
Readme
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
To use the all configuration, extend it in your .eslintrc
file:
{
"extends": ["plugin:vitest/all"]
}
Rules
⚠️ 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.
Name | Description | ⚠️ | 🔧 | 💡 |
---|---|---|---|---|
consistent-test-filename | forbidden .spec test file pattern | 🌐 | ||
consistent-test-it | Prefer test or it but not both | 🌐 | 🔧 | |
expect-expect | Enforce having expectation in test body | ✅ | ||
max-expects | Enforce a maximum number of expect per test | 🌐 | ||
max-nested-describe | Nested describe block should be less than set max value or default value | 🌐 | ||
no-alias-methods | Disallow alias methods | 🌐 | 🔧 | |
no-commented-out-tests | Disallow commented out tests | ✅ | ||
no-conditional-expect | Disallow conditional expects | 🌐 | ||
no-conditional-in-test | Disallow conditional tests | 🌐 | ||
no-conditional-tests | Disallow conditional tests | 🌐 | ||
no-disabled-tests | Disallow disabled tests | 🌐 | ||
no-done-callback | Disallow using a callback in asynchrounous tests and hooks | 🌐 | 💡 | |
no-duplicate-hooks | Disallow duplicate hooks and teardown hooks | 🌐 | ||
no-focused-tests | Disallow focused tests | 🌐 | 🔧 | |
no-hooks | Disallow setup and teardown hooks | 🌐 | ||
no-identical-title | Disallow identical titles | ✅ | 🔧 | |
no-interpolation-in-snapshots | Disallow string interpolation in snapshots | 🌐 | 🔧 | |
no-large-snapshots | Disallow large snapshots | 🌐 | ||
no-mocks-import | Disallow importing from mocks directory | 🌐 | ||
no-restricted-matchers | Disallow the use of certain matchers | 🌐 | ||
no-restricted-vi-methods | Disallow specific vi. methods |
🌐 | ||
no-skipped-tests | Disallow skipped tests | 🌐 | ||
no-standalone-expect | Disallow using expect outside of it or test blocks |
🌐 | ||
no-test-prefixes | Disallow using test as a prefix |
🌐 | 🔧 | |
no-test-return-statement | Disallow return statements in tests | 🌐 | ||
prefer-called-with | Suggest using toBeCalledWith() or toHaveBeenCalledWith() |
🌐 | ||
prefer-lowercase-title | Enforce lowercase titles | 🌐 | 🔧 | |
prefer-to-be | Suggest using toBe() | ✅ | 🔧 | |
valid-expect | Enforce valid expect() usage |
✅ | ||
valid-title | Enforce valid titles | ✅ | 🔧 |
Credits
- eslint-plugin-jest Most the rules are basically a port of jest plugin rules with small modifications