@@ -22,6 +22,15 @@ yarn add --dev eslint eslint-plugin-jest
22
22
23
23
## Usage
24
24
25
+ > [ !NOTE]
26
+ >
27
+ > ` eslint.config.js ` is supported, though most of the plugin documentation still
28
+ > currently uses ` .eslintrc ` syntax.
29
+ >
30
+ > Refer to the
31
+ > [ ESLint documentation on the new configuration file format] ( https://eslint.org/docs/latest/use/configure/configuration-files-new )
32
+ > for more.
33
+
25
34
Add ` jest ` to the plugins section of your ` .eslintrc ` configuration file. You
26
35
can omit the ` eslint-plugin- ` prefix:
27
36
@@ -85,7 +94,7 @@ test-related. This means it's generally not suitable to include them in your
85
94
top-level configuration as that applies to all files being linted which can
86
95
include source files.
87
96
88
- You can use
97
+ For ` .eslintrc ` configs you can use
89
98
[ overrides] ( https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work )
90
99
to have ESLint apply additional rules to specific files:
91
100
@@ -106,6 +115,30 @@ to have ESLint apply additional rules to specific files:
106
115
}
107
116
```
108
117
118
+ For ` eslint.config.js ` you can use
119
+ [ ` files ` and ` ignores ` ] ( https://eslint.org/docs/latest/use/configure/configuration-files-new#specifying-files-and-ignores ) :
120
+
121
+ ``` js
122
+ const jest = require (' eslint-plugin-jest' );
123
+
124
+ module .exports = [
125
+ ... require (' @eslint/js' ).configs .recommended ,
126
+ {
127
+ files: [' test/**' ],
128
+ ... jest .configs [' flat/recommended' ],
129
+ rules: {
130
+ ... jest .configs [' flat/recommended' ].rules ,
131
+ ' jest/prefer-expect-assertions' : ' off' ,
132
+ },
133
+ },
134
+ // you can also configure jest rules in other objects, so long as some of the `files` match
135
+ {
136
+ files: [' test/**' ],
137
+ rules: { ' jest/prefer-expect-assertions' : ' off' },
138
+ },
139
+ ];
140
+ ```
141
+
109
142
### Jest ` version ` setting
110
143
111
144
The behaviour of some rules (specifically [ ` no-deprecated-functions ` ] [ ] ) change
@@ -145,20 +178,41 @@ module.exports = {
145
178
146
179
## Shareable configurations
147
180
181
+ > [ !NOTE]
182
+ >
183
+ > ` eslint.config.js ` compatible versions of configs are available prefixed with
184
+ > ` flat/ ` and may be subject to small breaking changes while ESLint v9 is being
185
+ > finalized.
186
+
148
187
### Recommended
149
188
150
189
This plugin exports a recommended configuration that enforces good testing
151
190
practices.
152
191
153
- To enable this configuration use the ` extends ` property in your ` .eslintrc `
154
- config file:
192
+ To enable this configuration with ` .eslintrc ` , use the ` extends ` property:
155
193
156
194
``` json
157
195
{
158
196
"extends" : [" plugin:jest/recommended" ]
159
197
}
160
198
```
161
199
200
+ To enable this configuration with ` eslint.config.js ` , use
201
+ ` jest.configs['flat/recommended'] ` :
202
+
203
+ ``` js
204
+ const jest = require (' eslint-plugin-jest' );
205
+
206
+ module .exports = [
207
+ {
208
+ files: [
209
+ /* glob matching your test files */
210
+ ],
211
+ ... jest .configs [' flat/recommended' ],
212
+ },
213
+ ];
214
+ ```
215
+
162
216
### Style
163
217
164
218
This plugin also exports a configuration named ` style ` , which adds some
@@ -174,9 +228,21 @@ config file:
174
228
}
175
229
```
176
230
177
- See
178
- [ ESLint documentation] ( https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files )
179
- for more information about extending configuration files.
231
+ To enable this configuration with ` eslint.config.js ` , use
232
+ ` jest.configs['flat/style'] ` :
233
+
234
+ ``` js
235
+ const jest = require (' eslint-plugin-jest' );
236
+
237
+ module .exports = [
238
+ {
239
+ files: [
240
+ /* glob matching your test files */
241
+ ],
242
+ ... jest .configs [' flat/style' ],
243
+ },
244
+ ];
245
+ ```
180
246
181
247
### All
182
248
@@ -189,10 +255,55 @@ If you want to enable all rules instead of only some you can do so by adding the
189
255
}
190
256
```
191
257
258
+ To enable this configuration with ` eslint.config.js ` , use
259
+ ` jest.configs['flat/all'] ` :
260
+
261
+ ``` js
262
+ const jest = require (' eslint-plugin-jest' );
263
+
264
+ module .exports = [
265
+ {
266
+ files: [
267
+ /* glob matching your test files */
268
+ ],
269
+ ... jest .configs [' flat/all' ],
270
+ },
271
+ ];
272
+ ```
273
+
192
274
While the ` recommended ` and ` style ` configurations only change in major versions
193
275
the ` all ` configuration may change in any release and is thus unsuited for
194
276
installations requiring long-term consistency.
195
277
278
+ ## Snapshot processing
279
+
280
+ > [ !NOTE]
281
+ >
282
+ > This is only relevant for ` eslint.config.js `
283
+
284
+ This plugin provides a
285
+ [ custom processor] ( https://eslint.org/docs/latest/extend/custom-processors ) to
286
+ allow rules to "lint" snapshot files.
287
+
288
+ For ` .eslintrc ` based configs, this is automatically enabled out of the box but
289
+ must be opted into for ` eslint.config.js ` using the ` flat/snapshots ` config:
290
+
291
+ ``` js
292
+ const jest = require (' eslint-plugin-jest' );
293
+
294
+ module .exports = [
295
+ {
296
+ ... jest .configs [' flat/snapshots' ],
297
+ rules: {
298
+ ' jest/no-large-snapshots' : [' error' , { maxSize: 1 }],
299
+ },
300
+ },
301
+ ];
302
+ ```
303
+
304
+ Unlike other configs, this includes a ` files ` array that matches ` .snap ` files
305
+ meaning you can use it directly
306
+
196
307
## Rules
197
308
198
309
<!-- begin auto-generated rules list -->
0 commit comments