Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions docs/src/extend/custom-parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,17 @@ Then add the custom parser to your ESLint configuration file with the `languageO
```js
// eslint.config.js

const { defineConfig } = require("eslint/config");
const myparser = require("eslint-parser-myparser");

module.exports = [
module.exports = defineConfig([
{
languageOptions: {
parser: myparser,
},
// ... rest of configuration
},
];
]);
```

When using legacy configuration, specify the `parser` property as a string:
Expand Down Expand Up @@ -183,13 +184,15 @@ Include the custom parser in an ESLint configuration file:

```js
// eslint.config.js
module.exports = [
const { defineConfig } = require("eslint/config");

module.exports = defineConfig([
{
languageOptions: {
parser: require("./path/to/awesome-custom-parser"),
},
},
];
]);
```

Or if using legacy configuration:
Expand Down
73 changes: 45 additions & 28 deletions docs/src/use/configure/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ In flat config, you would do the same thing like this:
```javascript
// eslint.config.js

import { defineConfig } from "eslint/config";
import jsdoc from "eslint-plugin-jsdoc";

export default [
export default defineConfig([
{
files: ["**/*.js"],
plugins: {
Expand All @@ -93,7 +94,7 @@ export default [
"jsdoc/check-values": "error",
},
},
];
]);
```

::: tip
Expand Down Expand Up @@ -123,17 +124,18 @@ In flat config, you would do the same thing like this:
```javascript
// eslint.config.js

import { defineConfig } from "eslint/config";
import babelParser from "@babel/eslint-parser";

export default [
export default defineConfig([
{
// ...other config
languageOptions: {
parser: babelParser,
},
// ...other config
},
];
]);
```

### Processors
Expand Down Expand Up @@ -187,9 +189,10 @@ In flat config, the following are all valid ways to express the same:

```javascript
// eslint.config.js
import { defineConfig } from "eslint/config";
import somePlugin from "eslint-plugin-someplugin";

export default [
export default defineConfig([
{
plugins: { somePlugin },
processor: "somePlugin/someProcessor",
Expand All @@ -203,7 +206,7 @@ export default [
// We don't need the plugin to be present in the config to use the processor directly
processor: somePlugin.processors.someProcessor,
},
];
]);
```

Note that because the `.md` processor is _not_ automatically added by flat config, you also need to specify an extra configuration element:
Expand Down Expand Up @@ -265,9 +268,10 @@ For flat config, here is a configuration with the default glob pattern:
```javascript
// eslint.config.js

import { defineConfig } from "eslint/config";
import js from "@eslint/js";

export default [
export default defineConfig([
js.configs.recommended, // Recommended config applied to all files
// Override the recommended config
{
Expand All @@ -277,17 +281,18 @@ export default [
},
// ...other configuration
},
];
]);
```

A flat config example configuration supporting multiple configs for different glob patterns:

```javascript
// eslint.config.js

import { defineConfig } from "eslint/config";
import js from "@eslint/js";

export default [
export default defineConfig([
js.configs.recommended, // Recommended config applied to all files
// File-pattern specific overrides
{
Expand All @@ -303,7 +308,7 @@ export default [
},
},
// ...other configurations
];
]);
```

### Configuring Language Options
Expand Down Expand Up @@ -338,9 +343,10 @@ Here's the same configuration in flat config:
```javascript
// eslint.config.js

import { defineConfig } from "eslint/config";
import globals from "globals";

export default [
export default defineConfig([
{
languageOptions: {
ecmaVersion: 2022,
Expand All @@ -353,7 +359,7 @@ export default [
},
// ...other config
},
];
]);
```

::: tip
Expand Down Expand Up @@ -402,9 +408,10 @@ Another option is to remove the comment from the file being linted and define th
```javascript
// eslint.config.js

import { defineConfig } from "eslint/config";
import globals from "globals";

export default [
export default defineConfig([
// ...other config
{
files: ["tests/**"],
Expand All @@ -414,7 +421,7 @@ export default [
},
},
},
];
]);
```

### Predefined and Shareable Configs
Expand Down Expand Up @@ -475,11 +482,12 @@ To use the same configs in flat config, you would do the following:
```javascript
// eslint.config.js

import { defineConfig } from "eslint/config";
import js from "@eslint/js";
import customConfig from "./custom-config.js";
import myConfig from "eslint-config-my-config";

export default [
export default defineConfig([
js.configs.recommended,
customConfig,
myConfig,
Expand All @@ -489,24 +497,25 @@ export default [
},
// ...other config
},
];
]);
```

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:

```javascript
// eslint.config.js

import { defineConfig } from "eslint/config";
import js from "@eslint/js";
import customTestConfig from "./custom-test-config.js";

export default [
export default defineConfig([
js.configs.recommended,
{
...customTestConfig,
files: ["**/*.test.js"],
},
];
]);
```

#### Using eslintrc Configs in Flat Config
Expand All @@ -522,6 +531,7 @@ You may find that there's a shareable config you rely on that hasn't yet been up
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:

```js
import { defineConfig } from "eslint/config";
import { FlatCompat } from "@eslint/eslintrc";
import path from "path";
import { fileURLToPath } from "url";
Expand All @@ -534,10 +544,10 @@ const compat = new FlatCompat({
baseDirectory: __dirname,
});

export default [
export default defineConfig([
// mimic ESLintRC-style extends
...compat.extends("eslint-config-my-config"),
];
]);
```
This example uses the `FlatCompat#extends()` method to insert the `eslint-config-my-config` into the flat config array.
Expand Down Expand Up @@ -572,13 +582,15 @@ module.exports = {
The equivalent ignore patterns in flat config look like this:
```javascript
export default [
import { defineConfig } from "eslint/config";
export default defineConfig([
// ...other config
{
// Note: there should be no other properties in this object
ignores: ["**/temp.js", "config/*"],
},
];
]);
```
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.
Expand Down Expand Up @@ -610,15 +622,17 @@ Here's the same options in flat config:
```javascript
// eslint.config.js

export default [
import { defineConfig } from "eslint/config";

export default defineConfig([
{
// ...other config
linterOptions: {
noInlineConfig: true,
reportUnusedDisableDirectives: "warn",
},
},
];
]);
```
### CLI Flag Changes
Expand All @@ -637,9 +651,10 @@ The `--rulesdir` flag was used to load additional rules from a specified directo
```js
// eslint.config.js
import { defineConfig } from "eslint/config";
import myRule from "./rules/my-rule.js";

export default [
export default defineConfig([
{
// define the plugin
plugins: {
Expand All @@ -655,7 +670,7 @@ export default [
"local/my-rule": ["error"],
},
},
];
]);
```
#### `--ext`
Expand All @@ -664,13 +679,15 @@ The `--ext` flag was used to specify additional file extensions ESLint should se
```js
// eslint.config.js
export default [
import { defineConfig } from "eslint/config";

export default defineConfig([
{
files: ["**/*.ts", "**/*.tsx"],

// any additional configuration for these file types here
},
];
]);
```
ESLint uses the `files` keys from the config file to determine which files should be linted.
Expand Down
15 changes: 10 additions & 5 deletions docs/src/use/core-concepts/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ Each config file exports a [config array](#config-array) containing [config obje
For example, this `eslint.config.js` file enables the `prefer-const` [rule](#rule) at the _error_ [severity](#severity):

```js
export default [
import { defineConfig } from "eslint/config";

export default defineConfig([
{
rules: {
"prefer-const": "error",
},
},
];
]);
```

See [Configuration Files](../configure/configuration-files) for more details.
Expand Down Expand Up @@ -242,7 +244,9 @@ When a [config object](#config-object) or [inline config](#inline-config-configu
The following [config file](#config-file-configuration-file) overrides `no-unused-expressions` from `"error"` to `"off"` in `*.test.js` files:

```js
export default [
import { defineConfig } from "eslint/config";

export default defineConfig([
{
rules: {
"no-unused-expressions": "error",
Expand All @@ -254,7 +258,7 @@ export default [
"no-unused-expressions": "off",
},
},
];
]);
```

The following [inline config](#inline-config-configuration-comment) sets `no-unused-expressions` to `"error"`:
Expand Down Expand Up @@ -346,10 +350,11 @@ Many plugins provide configs with names like _"recommended"_ that enable their s
For example, [`eslint-plugin-solid`](https://github.com/solidjs-community/eslint-plugin-solid) provides a shareable recommended config:

```js
import { defineConfig } from "eslint/config";
import js from "@eslint/js";
import solid from "eslint-plugin-solid/configs/recommended";

export default [js.configs.recommended, solid];
export default defineConfig([js.configs.recommended, solid]);
```

For information on shareable configs, see [Share Configurations](../../extend/shareable-configs).
Expand Down
Loading