Skip to content

Commit 9be1963

Browse files
committed
docs: use ESLint extends
Since [March of this year][1], ESLint supports and [recommends][2] using `defineConfig` and `extends` for flat configurations (instead of having to manually spread the pieces of the configuration). [1]: https://eslint.org/blog/2025/03/flat-config-extends-define-config-global-ignores/ [2]: https://eslint.org/docs/latest/use/configure/configuration-files#extending-configurations
1 parent 4851e6b commit 9be1963

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ With
2929
just import the plugin and away you go:
3030

3131
```js
32+
const { defineConfig } = require('@eslint/config');
3233
const pluginJest = require('eslint-plugin-jest');
3334

34-
module.exports = [
35+
module.exports = defineConfig([
3536
{
3637
// update this to match your test files
3738
files: ['**/*.spec.js', '**/*.test.js'],
@@ -47,7 +48,7 @@ module.exports = [
4748
'jest/valid-expect': 'error',
4849
},
4950
},
50-
];
51+
]);
5152
```
5253

5354
With legacy configuration, add `jest` to the plugins section of your `.eslintrc`
@@ -146,15 +147,15 @@ For `eslint.config.js` you can use
146147
[`files` and `ignores`](https://eslint.org/docs/latest/use/configure/configuration-files-new#specifying-files-and-ignores):
147148

148149
```js
150+
const { defineConfig } = require('@eslint/config');
149151
const jest = require('eslint-plugin-jest');
150152

151-
module.exports = [
153+
module.exports = defaultConfig([
152154
...require('@eslint/js').configs.recommended,
153155
{
154156
files: ['test/**'],
155-
...jest.configs['flat/recommended'],
157+
extends: [jest.configs['flat/recommended']],
156158
rules: {
157-
...jest.configs['flat/recommended'].rules,
158159
'jest/prefer-expect-assertions': 'off',
159160
},
160161
},
@@ -163,7 +164,7 @@ module.exports = [
163164
files: ['test/**'],
164165
rules: { 'jest/prefer-expect-assertions': 'off' },
165166
},
166-
];
167+
]);
167168
```
168169

169170
### Jest `version` setting
@@ -228,16 +229,17 @@ To enable this configuration with `eslint.config.js`, use
228229
`jest.configs['flat/recommended']`:
229230

230231
```js
232+
const { defineConfig } = require('@eslint/config');
231233
const jest = require('eslint-plugin-jest');
232234

233-
module.exports = [
235+
module.exports = defineConfig([
234236
{
235237
files: [
236238
/* glob matching your test files */
237239
],
238-
...jest.configs['flat/recommended'],
240+
extends: [jest.configs['flat/recommended']],
239241
},
240-
];
242+
]);
241243
```
242244

243245
### Style
@@ -259,16 +261,17 @@ To enable this configuration with `eslint.config.js`, use
259261
`jest.configs['flat/style']`:
260262

261263
```js
264+
const { defineConfig } = require('@eslint/config');
262265
const jest = require('eslint-plugin-jest');
263266

264-
module.exports = [
267+
module.exports = defineConfig([
265268
{
266269
files: [
267270
/* glob matching your test files */
268271
],
269-
...jest.configs['flat/style'],
272+
extends: [jest.configs['flat/style']],
270273
},
271-
];
274+
]);
272275
```
273276

274277
### All
@@ -286,16 +289,17 @@ To enable this configuration with `eslint.config.js`, use
286289
`jest.configs['flat/all']`:
287290

288291
```js
292+
const { defineConfig } = require('@eslint/config');
289293
const jest = require('eslint-plugin-jest');
290294

291-
module.exports = [
295+
module.exports = defineConfig([
292296
{
293297
files: [
294298
/* glob matching your test files */
295299
],
296-
...jest.configs['flat/all'],
300+
extends: [jest.configs['flat/all']],
297301
},
298-
];
302+
]);
299303
```
300304

301305
While the `recommended` and `style` configurations only change in major versions

0 commit comments

Comments
 (0)