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
Addvitest
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-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-equality-matcher | Suggest using the built-in quality matchers | π | | π‘ |
| prefer-expect-resolves | Suggest using expect().resolves
over expect(await ...)
syntax | π | π§ | |
| prefer-lowercase-title | Enforce lowercase titles | π | π§ | |
| prefer-strict-equal | Prefer strict equal over equal | π | | π‘ |
| prefer-to-be | Suggest using toBe() | β
| π§ | |
| prefer-to-be-falsy | Suggest using toBeFalsy() | π | π§ | |
| prefer-to-be-object | Prefer toBeObject() | π | π§ | |
| prefer-to-be-truthy | Suggest using toBeTruthy
| π | π§ | |
| prefer-to-have-length | Suggest using toHaveLength() | π | π§ | |
| valid-expect | Enforce valid expect()
usage | β
| | |
| valid-title | Enforce valid titles | β
| π§ | |Credits
Most of the rules in this plugin are essentially ports of Jest plugin rules with minor modifications