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
+39-5Lines changed: 39 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,7 +211,7 @@ In eslintrc files, you configure various language options across the `env`, `glo
211
211
212
212
In flat config files, the `globals`, and `parserOptions` are consolidated under the `languageOptions` key; the `env` property doesn't exist. Groups of global variables for specific runtimes are imported from the [globals](https://www.npmjs.com/package/globals) npm package and included in the `globals` property. You can use the spread operator (`...`) to import multiple globals at once.
213
213
214
-
For example, here's a eslintrc file with language options:
214
+
For example, here's an eslintrc file with language options:
215
215
216
216
```javascript
217
217
// .eslintrc.js
@@ -314,14 +314,14 @@ export default [
314
314
];
315
315
```
316
316
317
-
### Predefined Configs
317
+
### Predefined and Shareable Configs
318
318
319
-
In eslintrc files, use the `extends` property to use predefined configs. ESLint comes with two predefined configs that you can access as strings:
319
+
In eslintrc files, use the `extends` property to use predefined and shareable configs. ESLint comes with two predefined configs that you can access as strings:
320
320
321
321
*`"eslint:recommended"`: the rules recommended by ESLint
322
322
*`"eslint:all"`: all rules shipped with ESLint
323
323
324
-
You can also use the `extends` property to extend a custom config. Custom configs can either be paths to local config files or npm package names.
324
+
You can also use the `extends` property to extend a shareable config. Shareable configs can either be paths to local config files or npm package names.
325
325
326
326
In flat config files, predefined configs are imported from separate modules into flat config files. The `recommended` and `all` rules configs are located in the [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) package. You must import this package to use these configs:
327
327
@@ -346,7 +346,7 @@ module.exports = {
346
346
}
347
347
```
348
348
349
-
This eslintrc file uses built-in config, local custom config, and custom config from an npm package:
349
+
This eslintrc file uses built-in config, local custom config, and shareable config from an npm package:
350
350
351
351
```javascript
352
352
// .eslintrc.js
@@ -400,6 +400,40 @@ export default [
400
400
];
401
401
```
402
402
403
+
#### Using eslintrc Configs in Flat Config
404
+
405
+
You may find that there's a shareable config you rely on that hasn't yet been updated to flat config format. In that case, you can use the `FlatCompat` utility to translate the eslintrc format into flat config format. First, install the `@eslint/eslintrc` package:
406
+
407
+
```shell
408
+
npm install @eslint/eslintrc --save-dev
409
+
```
410
+
411
+
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:
412
+
413
+
```js
414
+
import { FlatCompat } from"@eslint/eslintrc";
415
+
importpathfrom"path";
416
+
import { fileURLToPath } from"url";
417
+
418
+
// mimic CommonJS variables -- not needed if using CommonJS
419
+
const__filename=fileURLToPath(import.meta.url);
420
+
const__dirname=path.dirname(__filename);
421
+
422
+
constcompat=newFlatCompat({
423
+
baseDirectory:__dirname
424
+
});
425
+
426
+
exportdefault [
427
+
428
+
// mimic ESLintRC-style extends
429
+
...compat.extends("eslint-config-my-config"),
430
+
];
431
+
```
432
+
433
+
This example uses the `FlatCompat#extends()` method to insert the `eslint-config-my-config` into the flat config array.
434
+
435
+
For more information about the `FlatCompat` class, please see the [package README](https://github.com/eslint/eslintrc#usage).
436
+
403
437
### Ignoring Files
404
438
405
439
With eslintrc, you can make ESLint ignore files by creating a separate `.eslintignore` file in the root of your project. The `.eslintignore` file uses the same glob pattern syntax as `.gitignore` files. Alternatively, you can use an `ignorePatterns` property in your eslintrc file.
0 commit comments