@vitest/eslint-plugin 1.3.26 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -43
- package/dist/index.cjs +3593 -3623
- package/dist/index.d.cts +56 -828
- package/dist/index.d.ts +56 -829
- package/dist/index.js +3593 -3623
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -24,20 +24,19 @@ npm install @vitest/eslint-plugin --save-dev
|
|
|
24
24
|
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.
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
|
+
import { defineConfig } from 'eslint/config'
|
|
27
28
|
import vitest from '@vitest/eslint-plugin'
|
|
28
29
|
|
|
29
|
-
export default
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
rules
|
|
36
|
-
|
|
37
|
-
'vitest/max-nested-describe': ['error', { max: 3 }], // you can also modify rules' behavior using option like this
|
|
38
|
-
},
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
files: ['tests/**'], // or any other pattern
|
|
32
|
+
plugins: {
|
|
33
|
+
vitest,
|
|
34
|
+
},
|
|
35
|
+
rules: {
|
|
36
|
+
...vitest.configs.recommended.rules, // you can also use vitest.configs.all.rules to enable all rules
|
|
37
|
+
'vitest/max-nested-describe': ['error', { max: 3 }], // you can also modify rules' behavior using option like this
|
|
39
38
|
},
|
|
40
|
-
|
|
39
|
+
})
|
|
41
40
|
```
|
|
42
41
|
|
|
43
42
|
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
|
|
@@ -80,9 +79,20 @@ Vitest ships with an optional [type-testing feature](https://vitest.dev/guide/te
|
|
|
80
79
|
If you're using this feature, you should also enabled `typecheck` in the settings for this plugin. This ensures that rules like [expect-expect](docs/rules/expect-expect.md) account for type-related assertions in tests.
|
|
81
80
|
|
|
82
81
|
```js
|
|
82
|
+
import { defineConfig } from 'eslint/config'
|
|
83
|
+
import tseslint from 'typescript-eslint'
|
|
83
84
|
import vitest from '@vitest/eslint-plugin'
|
|
84
85
|
|
|
85
|
-
export default
|
|
86
|
+
export default defineConfig(
|
|
87
|
+
// see https://typescript-eslint.io
|
|
88
|
+
tseslint.configs.recommended,
|
|
89
|
+
{
|
|
90
|
+
languageOptions: {
|
|
91
|
+
parserOptions: {
|
|
92
|
+
projectService: true,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
86
96
|
{
|
|
87
97
|
files: ['tests/**'], // or any other pattern
|
|
88
98
|
plugins: {
|
|
@@ -102,7 +112,7 @@ export default [
|
|
|
102
112
|
},
|
|
103
113
|
},
|
|
104
114
|
},
|
|
105
|
-
|
|
115
|
+
)
|
|
106
116
|
```
|
|
107
117
|
|
|
108
118
|
### Custom Fixtures
|
|
@@ -110,24 +120,23 @@ export default [
|
|
|
110
120
|
If you're using custom fixtures in a separate file and importing them in your tests, you can let the plugin know about them by adding them to the `vitestImports` setting. The property accepts an array of strings or regular expressions that match the module names where your custom fixtures are defined.
|
|
111
121
|
|
|
112
122
|
```js
|
|
123
|
+
import { defineConfig } from 'eslint/config'
|
|
113
124
|
import vitest from '@vitest/eslint-plugin'
|
|
114
125
|
|
|
115
|
-
export default
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
rules
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
vitestImports: ['@/tests/fixtures', /test-extend$/],
|
|
127
|
-
},
|
|
126
|
+
export default defineConfig({
|
|
127
|
+
files: ['tests/**'], // or any other pattern
|
|
128
|
+
plugins: {
|
|
129
|
+
vitest,
|
|
130
|
+
},
|
|
131
|
+
rules: {
|
|
132
|
+
...vitest.configs.recommended.rules,
|
|
133
|
+
},
|
|
134
|
+
settings: {
|
|
135
|
+
vitest: {
|
|
136
|
+
vitestImports: ['@/tests/fixtures', /test-extend$/],
|
|
128
137
|
},
|
|
129
138
|
},
|
|
130
|
-
|
|
139
|
+
})
|
|
131
140
|
```
|
|
132
141
|
|
|
133
142
|
### Shareable Configurations
|
|
@@ -139,14 +148,13 @@ This plugin exports a recommended configuration that enforces good testing pract
|
|
|
139
148
|
To enable this configuration with `eslint.config.js`, use `vitest.configs.recommended`:
|
|
140
149
|
|
|
141
150
|
```js
|
|
151
|
+
import { defineConfig } from 'eslint/config'
|
|
142
152
|
import vitest from '@vitest/eslint-plugin'
|
|
143
153
|
|
|
144
|
-
export default
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
},
|
|
149
|
-
]
|
|
154
|
+
export default defineConfig({
|
|
155
|
+
files: ['tests/**'], // or any other pattern
|
|
156
|
+
...vitest.configs.recommended,
|
|
157
|
+
})
|
|
150
158
|
```
|
|
151
159
|
|
|
152
160
|
#### All
|
|
@@ -154,14 +162,13 @@ export default [
|
|
|
154
162
|
If you want to enable all rules instead of only some you can do so by adding the all configuration to your `eslint.config.js` config file:
|
|
155
163
|
|
|
156
164
|
```js
|
|
165
|
+
import { defineConfig } from 'eslint/config'
|
|
157
166
|
import vitest from '@vitest/eslint-plugin'
|
|
158
167
|
|
|
159
|
-
export default
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
},
|
|
164
|
-
]
|
|
168
|
+
export default defineConfig({
|
|
169
|
+
files: ['tests/**'], // or any other pattern
|
|
170
|
+
...vitest.configs.all,
|
|
171
|
+
})
|
|
165
172
|
```
|
|
166
173
|
|
|
167
174
|
### Rules
|
|
@@ -178,9 +185,9 @@ export default [
|
|
|
178
185
|
💭 Requires [type information](https://typescript-eslint.io/linting/typed-linting).\
|
|
179
186
|
❌ Deprecated.
|
|
180
187
|
|
|
181
|
-
| Name
|
|
188
|
+
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 | ❌ |
|
|
182
189
|
| :----------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------- | :-- | :-- | :-- | :-- | :-- | :-- | :-- |
|
|
183
|
-
| [consistent-test-filename](docs/rules/consistent-test-filename.md) | require
|
|
190
|
+
| [consistent-test-filename](docs/rules/consistent-test-filename.md) | require test file pattern | | 🌐 | | | | | |
|
|
184
191
|
| [consistent-test-it](docs/rules/consistent-test-it.md) | enforce using test or it but not both | | 🌐 | | 🔧 | | | |
|
|
185
192
|
| [consistent-vitest-vi](docs/rules/consistent-vitest-vi.md) | enforce using vitest or vi but not both | | 🌐 | | 🔧 | | | |
|
|
186
193
|
| [expect-expect](docs/rules/expect-expect.md) | enforce having expectation in test body | ✅ | 🌐 | | | | | |
|
|
@@ -193,7 +200,7 @@ export default [
|
|
|
193
200
|
| [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | disallow conditional tests | | 🌐 | | | | | |
|
|
194
201
|
| [no-conditional-tests](docs/rules/no-conditional-tests.md) | disallow conditional tests | | 🌐 | | | | | |
|
|
195
202
|
| [no-disabled-tests](docs/rules/no-disabled-tests.md) | disallow disabled tests | | 🌐 | | | | | |
|
|
196
|
-
| [no-done-callback](docs/rules/no-done-callback.md) | disallow using a callback in asynchronous tests and hooks | |
|
|
203
|
+
| [no-done-callback](docs/rules/no-done-callback.md) | disallow using a callback in asynchronous tests and hooks | | | | | 💡 | | ❌ |
|
|
197
204
|
| [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | disallow duplicate hooks and teardown hooks | | 🌐 | | | | | |
|
|
198
205
|
| [no-focused-tests](docs/rules/no-focused-tests.md) | disallow focused tests | | 🌐 | | 🔧 | | | |
|
|
199
206
|
| [no-hooks](docs/rules/no-hooks.md) | disallow setup and teardown hooks | | 🌐 | | | | | |
|
|
@@ -229,6 +236,7 @@ export default [
|
|
|
229
236
|
| [prefer-expect-type-of](docs/rules/prefer-expect-type-of.md) | enforce using `expectTypeOf` instead of `expect(typeof ...)` | | 🌐 | | 🔧 | | | |
|
|
230
237
|
| [prefer-hooks-in-order](docs/rules/prefer-hooks-in-order.md) | enforce having hooks in consistent order | | 🌐 | | | | | |
|
|
231
238
|
| [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | enforce having hooks before any test cases | | 🌐 | | | | | |
|
|
239
|
+
| [prefer-import-in-mock](docs/rules/prefer-import-in-mock.md) | prefer dynamic import in mock | | 🌐 | | 🔧 | | | |
|
|
232
240
|
| [prefer-importing-vitest-globals](docs/rules/prefer-importing-vitest-globals.md) | enforce importing Vitest globals | | 🌐 | | 🔧 | | | |
|
|
233
241
|
| [prefer-lowercase-title](docs/rules/prefer-lowercase-title.md) | enforce lowercase titles | | 🌐 | | 🔧 | | | |
|
|
234
242
|
| [prefer-mock-promise-shorthand](docs/rules/prefer-mock-promise-shorthand.md) | enforce mock resolved/rejected shorthands for promises | | 🌐 | | 🔧 | | | |
|
|
@@ -254,7 +262,6 @@ export default [
|
|
|
254
262
|
| [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | require promises that have expectations in their chain to be valid | | 🌐 | | | | | |
|
|
255
263
|
| [valid-title](docs/rules/valid-title.md) | enforce valid titles | ✅ | 🌐 | | 🔧 | | | |
|
|
256
264
|
| [warn-todo](docs/rules/warn-todo.md) | disallow `.todo` usage | | | | | | | |
|
|
257
|
-
| [prefer-import-in-moc](docs/rules/prefer-import-in-moc.md) | enforce dynamic import in mock | ✅ | 🌐 | | 🔧 | | | |
|
|
258
265
|
|
|
259
266
|
<!-- end auto-generated rules list -->
|
|
260
267
|
|