You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/use/configure/migration-guide.md
+45-28Lines changed: 45 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,9 +80,10 @@ In flat config, you would do the same thing like this:
80
80
```javascript
81
81
// eslint.config.js
82
82
83
+
import { defineConfig } from"eslint/config";
83
84
importjsdocfrom"eslint-plugin-jsdoc";
84
85
85
-
exportdefault [
86
+
exportdefaultdefineConfig([
86
87
{
87
88
files: ["**/*.js"],
88
89
plugins: {
@@ -93,7 +94,7 @@ export default [
93
94
"jsdoc/check-values":"error",
94
95
},
95
96
},
96
-
];
97
+
]);
97
98
```
98
99
99
100
::: tip
@@ -123,17 +124,18 @@ In flat config, you would do the same thing like this:
123
124
```javascript
124
125
// eslint.config.js
125
126
127
+
import { defineConfig } from"eslint/config";
126
128
importbabelParserfrom"@babel/eslint-parser";
127
129
128
-
exportdefault [
130
+
exportdefaultdefineConfig([
129
131
{
130
132
// ...other config
131
133
languageOptions: {
132
134
parser: babelParser,
133
135
},
134
136
// ...other config
135
137
},
136
-
];
138
+
]);
137
139
```
138
140
139
141
### Processors
@@ -187,9 +189,10 @@ In flat config, the following are all valid ways to express the same:
187
189
188
190
```javascript
189
191
// eslint.config.js
192
+
import { defineConfig } from"eslint/config";
190
193
importsomePluginfrom"eslint-plugin-someplugin";
191
194
192
-
exportdefault [
195
+
exportdefaultdefineConfig([
193
196
{
194
197
plugins: { somePlugin },
195
198
processor:"somePlugin/someProcessor",
@@ -203,7 +206,7 @@ export default [
203
206
// We don't need the plugin to be present in the config to use the processor directly
204
207
processor:somePlugin.processors.someProcessor,
205
208
},
206
-
];
209
+
]);
207
210
```
208
211
209
212
Note that because the `.md` processor is _not_ automatically added by flat config, you also need to specify an extra configuration element:
@@ -265,9 +268,10 @@ For flat config, here is a configuration with the default glob pattern:
265
268
```javascript
266
269
// eslint.config.js
267
270
271
+
import { defineConfig } from"eslint/config";
268
272
importjsfrom"@eslint/js";
269
273
270
-
exportdefault [
274
+
exportdefaultdefineConfig([
271
275
js.configs.recommended, // Recommended config applied to all files
272
276
// Override the recommended config
273
277
{
@@ -277,17 +281,18 @@ export default [
277
281
},
278
282
// ...other configuration
279
283
},
280
-
];
284
+
]);
281
285
```
282
286
283
287
A flat config example configuration supporting multiple configs for different glob patterns:
284
288
285
289
```javascript
286
290
// eslint.config.js
287
291
292
+
import { defineConfig } from"eslint/config";
288
293
importjsfrom"@eslint/js";
289
294
290
-
exportdefault [
295
+
exportdefaultdefineConfig([
291
296
js.configs.recommended, // Recommended config applied to all files
292
297
// File-pattern specific overrides
293
298
{
@@ -303,7 +308,7 @@ export default [
303
308
},
304
309
},
305
310
// ...other configurations
306
-
];
311
+
]);
307
312
```
308
313
309
314
### Configuring Language Options
@@ -338,9 +343,10 @@ Here's the same configuration in flat config:
338
343
```javascript
339
344
// eslint.config.js
340
345
346
+
import { defineConfig } from"eslint/config";
341
347
importglobalsfrom"globals";
342
348
343
-
exportdefault [
349
+
exportdefaultdefineConfig([
344
350
{
345
351
languageOptions: {
346
352
ecmaVersion:2022,
@@ -353,7 +359,7 @@ export default [
353
359
},
354
360
// ...other config
355
361
},
356
-
];
362
+
]);
357
363
```
358
364
359
365
::: tip
@@ -402,9 +408,10 @@ Another option is to remove the comment from the file being linted and define th
402
408
```javascript
403
409
// eslint.config.js
404
410
411
+
import { defineConfig } from"eslint/config";
405
412
importglobalsfrom"globals";
406
413
407
-
exportdefault [
414
+
exportdefaultdefineConfig([
408
415
// ...other config
409
416
{
410
417
files: ["tests/**"],
@@ -414,7 +421,7 @@ export default [
414
421
},
415
422
},
416
423
},
417
-
];
424
+
]);
418
425
```
419
426
420
427
### Predefined and Shareable Configs
@@ -475,11 +482,12 @@ To use the same configs in flat config, you would do the following:
475
482
```javascript
476
483
// eslint.config.js
477
484
485
+
import { defineConfig } from"eslint/config";
478
486
importjsfrom"@eslint/js";
479
487
importcustomConfigfrom"./custom-config.js";
480
488
importmyConfigfrom"eslint-config-my-config";
481
489
482
-
exportdefault [
490
+
exportdefaultdefineConfig([
483
491
js.configs.recommended,
484
492
customConfig,
485
493
myConfig,
@@ -489,24 +497,25 @@ export default [
489
497
},
490
498
// ...other config
491
499
},
492
-
];
500
+
]);
493
501
```
494
502
495
503
Note that because you are just importing JavaScript modules, you can mutate the config objects before ESLint uses them. For example, you might want to have a certain config object only apply to your test files:
@@ -522,6 +531,7 @@ You may find that there's a shareable config you rely on that hasn't yet been up
522
531
Then, import `FlatCompat` and create a new instance to convert an existing eslintrc config. For example, if the npm package `eslint-config-my-config` is in eslintrc format, you can write this:
523
532
524
533
```js
534
+
import { defineConfig } from"eslint/config";
525
535
import { FlatCompat } from"@eslint/eslintrc";
526
536
importpathfrom"path";
527
537
import { fileURLToPath } from"url";
@@ -534,10 +544,10 @@ const compat = new FlatCompat({
534
544
baseDirectory:__dirname,
535
545
});
536
546
537
-
exportdefault [
547
+
exportdefaultdefineConfig([
538
548
// mimic ESLintRC-style extends
539
549
...compat.extends("eslint-config-my-config"),
540
-
];
550
+
]);
541
551
```
542
552
543
553
This example uses the `FlatCompat#extends()` method to insert the `eslint-config-my-config` into the flat config array.
@@ -572,13 +582,15 @@ module.exports = {
572
582
The equivalent ignore patterns in flat config look like this:
573
583
574
584
```javascript
575
-
export default [
585
+
import { defineConfig } from "eslint/config";
586
+
587
+
export default defineConfig([
576
588
// ...other config
577
589
{
578
590
// Note: there should be no other properties in this object
579
591
ignores: ["**/temp.js", "config/*"],
580
592
},
581
-
];
593
+
]);
582
594
```
583
595
584
596
In `.eslintignore`, `temp.js` ignores all files named `temp.js`, whereas in flat config, you need to specify this as `**/temp.js`. The pattern `temp.js` in flat config only ignores a file named `temp.js` in the same directory as the configuration file.
@@ -610,15 +622,17 @@ Here's the same options in flat config:
610
622
```javascript
611
623
// eslint.config.js
612
624
613
-
exportdefault [
625
+
import { defineConfig } from"eslint/config";
626
+
627
+
exportdefaultdefineConfig([
614
628
{
615
629
// ...other config
616
630
linterOptions: {
617
631
noInlineConfig:true,
618
632
reportUnusedDisableDirectives:"warn",
619
633
},
620
634
},
621
-
];
635
+
]);
622
636
```
623
637
624
638
### CLI Flag Changes
@@ -637,9 +651,10 @@ The `--rulesdir` flag was used to load additional rules from a specified directo
637
651
638
652
```js
639
653
// eslint.config.js
654
+
import { defineConfig } from"eslint/config";
640
655
importmyRulefrom"./rules/my-rule.js";
641
656
642
-
exportdefault [
657
+
exportdefaultdefineConfig([
643
658
{
644
659
// define the plugin
645
660
plugins: {
@@ -655,7 +670,7 @@ export default [
655
670
"local/my-rule": ["error"],
656
671
},
657
672
},
658
-
];
673
+
]);
659
674
```
660
675
661
676
#### `--ext`
@@ -664,13 +679,15 @@ The `--ext` flag was used to specify additional file extensions ESLint should se
664
679
665
680
```js
666
681
// eslint.config.js
667
-
exportdefault [
682
+
import { defineConfig } from"eslint/config";
683
+
684
+
exportdefaultdefineConfig([
668
685
{
669
686
files: ["**/*.ts", "**/*.tsx"],
670
687
671
688
// any additional configuration for these file types here
672
689
},
673
-
];
690
+
]);
674
691
```
675
692
676
693
ESLint uses the `files` keys from the config file to determine which files should be linted.
0 commit comments