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/extend/custom-processors.md
+12-6Lines changed: 12 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -152,17 +152,19 @@ Example:
152
152
153
153
```js
154
154
// eslint.config.js
155
+
import { defineConfig } from "eslint/config";
155
156
import example from "eslint-plugin-example";
156
157
157
-
export default [
158
+
export default defineConfig([
158
159
{
160
+
files: ["**/*.txt"], // apply processor to text files
159
161
plugins: {
160
162
example
161
163
},
162
164
processor: "example/processor-name"
163
165
},
164
166
// ... other configs
165
-
];
167
+
]);
166
168
```
167
169
168
170
Inthisexample, theprocessornameis`"example/processor-name"`, andthat's the value that will be used for serializing configurations.
@@ -175,14 +177,16 @@ Example:
175
177
176
178
```js
177
179
// eslint.config.js
180
+
import { defineConfig } from "eslint/config";
178
181
import example from "eslint-plugin-example";
179
182
180
-
export default [
183
+
export default defineConfig([
181
184
{
185
+
files: ["**/*.txt"],
182
186
processor: example.processors["processor-name"]
183
187
},
184
188
// ... other configs
185
-
];
189
+
]);
186
190
```
187
191
188
192
Inthisexample, specifying`example.processors["processor-name"]`directlyusestheprocessor's own `meta` object, which must be defined to ensure proper handling when the processor is not referenced through the plugin name.
@@ -197,16 +201,18 @@ In order to use a processor from a plugin in a configuration file, import the pl
197
201
198
202
```js
199
203
// eslint.config.js
204
+
import { defineConfig } from "eslint/config";
200
205
import example from "eslint-plugin-example";
201
206
202
-
export default [
207
+
export default defineConfig([
203
208
{
209
+
files: ["**/*.txt"],
204
210
plugins: {
205
211
example
206
212
},
207
213
processor: "example/processor-name"
208
214
}
209
-
];
215
+
]);
210
216
```
211
217
212
218
See [SpecifyaProcessor](../use/configure/plugins#specify-a-processor) inthePluginConfigurationdocumentationformoredetails.
Copy file name to clipboardExpand all lines: docs/src/extend/plugin-migration-flat-config.md
+24-27Lines changed: 24 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,16 +114,18 @@ module.exports = plugin;
114
114
In order to use this renamed processor, you'll also need to manually specify it inside of a config, such as:
115
115
116
116
```js
117
+
import { defineConfig } from"eslint/config";
117
118
importexamplefrom"eslint-plugin-example";
118
119
119
-
exportdefault [
120
+
exportdefaultdefineConfig([
120
121
{
122
+
files: ["**/*.md"],
121
123
plugins: {
122
124
example
123
125
},
124
126
processor:"example/markdown"
125
127
}
126
-
];
128
+
]);
127
129
```
128
130
129
131
You should update your plugin's documentation to advise your users if you have renamed a file extension-named processor.
@@ -185,20 +187,23 @@ module.exports = plugin;
185
187
Your users can then use this exported config like this:
186
188
187
189
```js
190
+
import { defineConfig } from"eslint/config";
188
191
importexamplefrom"eslint-plugin-example";
189
192
190
-
exportdefault [
193
+
exportdefaultdefineConfig([
191
194
192
-
// use recommended config
193
-
example.configs.recommended,
194
-
195
-
// and provide your own overrides
195
+
// use recommended config and provide your own overrides
196
196
{
197
+
files: ["**/*.js"],
198
+
plugins: {
199
+
example
200
+
},
201
+
extends: ["example/recommended"],
197
202
rules: {
198
203
"example/rule1":"warn"
199
204
}
200
205
}
201
-
];
206
+
]);
202
207
```
203
208
204
209
If your config extends other configs, you can export an array:
@@ -223,19 +228,6 @@ module.exports = {
223
228
224
229
You should update your documentation so your plugin users know how to reference the exported configs.
225
230
226
-
If your exported config is an object, then your users can insert it directly into the config array; if your exported config is an array, then your users should use the spread operator (`...`) to insert the array's items into the config array.
227
-
228
-
Here's an example with both an object config and an array config:
229
-
230
-
```js
231
-
importexamplefrom"eslint-plugin-example";
232
-
233
-
exportdefault [
234
-
example.configs.recommended, // Object, so don't spread
235
-
...example.configs.extendedConfig, // Array, so needs spreading
236
-
];
237
-
```
238
-
239
231
For more information, see the [full documentation](https://eslint.org/docs/latest/extend/plugins#configs-in-plugins).
240
232
241
233
## Migrating Environments for Flat Config
@@ -295,22 +287,27 @@ module.exports = plugin;
295
287
Your users can then use this exported config like this:
296
288
297
289
```js
290
+
import { defineConfig } from"eslint/config";
298
291
importexamplefrom"eslint-plugin-example";
299
292
300
-
exportdefault [
293
+
exportdefaultdefineConfig([
294
+
{
295
+
files: ["**/tests/*.js"],
296
+
plugins: {
297
+
example
298
+
},
301
299
302
-
// use the mocha globals
303
-
example.configs.mocha,
300
+
// use the mocha globals
301
+
extends: ["example/mocha"],
304
302
305
-
// and provide your own overrides
306
-
{
303
+
// and provide your own overrides
307
304
languageOptions: {
308
305
globals: {
309
306
it:"readonly"
310
307
}
311
308
}
312
309
}
313
-
];
310
+
]);
314
311
```
315
312
316
313
You should update your documentation so your plugin users know how to reference the exported configs.
Copy file name to clipboardExpand all lines: docs/src/extend/plugins.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,9 +145,10 @@ In order to use a rule from a plugin in a configuration file, import the plugin
145
145
146
146
```js
147
147
// eslint.config.js
148
+
import { defineConfig } from"eslint/config";
148
149
importexamplefrom"eslint-plugin-example";
149
150
150
-
exportdefault [
151
+
exportdefaultdefineConfig([
151
152
{
152
153
plugins: {
153
154
example
@@ -156,7 +157,7 @@ export default [
156
157
"example/dollar-sign":"error"
157
158
}
158
159
}
159
-
];
160
+
]);
160
161
```
161
162
162
163
::: warning
@@ -192,16 +193,18 @@ In order to use a processor from a plugin in a configuration file, import the pl
192
193
193
194
```js
194
195
// eslint.config.js
196
+
import { defineConfig } from"eslint/config";
195
197
importexamplefrom"eslint-plugin-example";
196
198
197
-
exportdefault [
199
+
exportdefaultdefineConfig([
198
200
{
201
+
files: ["**/*.txt"],
199
202
plugins: {
200
203
example
201
204
},
202
205
processor:"example/processor-name"
203
206
}
204
-
];
207
+
]);
205
208
```
206
209
207
210
### Configs in Plugins
@@ -257,15 +260,26 @@ module.exports = plugin;
257
260
258
261
This plugin exports a `recommended` config that is an array with one config object. When there is just one config object, you can also export just the object without an enclosing array.
259
262
260
-
In order to use a config from a plugin in a configuration file, import the plugin and access the config directly through the plugin object. Assuming the config is an array, use the spread operator to add it into the array returned from the configuration file, like this:
263
+
::: tip
264
+
Your plugin can export both current (flat config) and legacy (eslintrc) config objects in the `configs` key. When exporting legacy configs, we recommend prefixing the name with `"legacy-"` (for example, `"legacy-recommended"`) to make it clear how the config should be used.
265
+
:::
266
+
267
+
In order to use a config from a plugin in a configuration file, import the plugin and use the `extends` key to reference the name of the config, like this:
261
268
262
269
```js
263
270
// eslint.config.js
271
+
import { defineConfig } from"eslint/config";
264
272
importexamplefrom"eslint-plugin-example";
265
273
266
-
exportdefault [
267
-
...example.configs.recommended
268
-
];
274
+
exportdefaultdefineConfig([
275
+
{
276
+
files: ["**/*.js"], // any patterns you want to apply the config to
Copy file name to clipboardExpand all lines: docs/src/use/configure/configuration-files.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,7 @@ Each configuration object contains all of the information ESLint needs to execut
69
69
*`name` - A name for the configuration object. This is used in error messages and config inspector to help identify which configuration object is being used. ([Naming Convention](#configuration-naming-conventions))
70
70
*`files` - An array of glob patterns indicating the files that the configuration object should apply to. If not specified, the configuration object applies to all files matched by any other configuration object.
71
71
*`ignores` - An array of glob patterns indicating the files that the configuration object should not apply to. If not specified, the configuration object applies to all files matched by `files`. If `ignores` is used without any other keys in the configuration object, then the patterns act as [global ignores](#globally-ignoring-files-with-ignores) and it gets applied to every configuration object.
72
+
*`extends` - An array of strings, configuration objects, or configuration arrays that contain additional configuration to apply.
72
73
*`languageOptions` - An object containing settings related to how JavaScript is configured for linting.
73
74
*`ecmaVersion` - The version of ECMAScript to support. May be any year (i.e., `2022`) or version (i.e., `5`). Set to `"latest"` for the most recent supported version. (default: `"latest"`)
74
75
*`sourceType` - The type of JavaScript source code. Possible values are `"script"` for traditional script files, `"module"` for ECMAScript modules (ESM), and `"commonjs"` for CommonJS files. (default: `"module"` for `.js` and `.mjs` files; `"commonjs"` for `.cjs` files)
@@ -490,6 +491,7 @@ import { defineConfig } from "eslint/config";
490
491
491
492
exportdefaultdefineConfig([
492
493
{
494
+
files: ["**/*.js"],
493
495
plugins: {
494
496
example: examplePlugin
495
497
},
@@ -509,6 +511,7 @@ import { defineConfig } from "eslint/config";
In this case, the configuration named `recommended` from `eslint-plugin-example` is accessed directly through the plugin object's `configs` property.
521
524
525
+
::: important
526
+
It's recommended to always use a `files` key when you use the `extends` key to ensure that your configuration applies to the correct files. By omitting the `files` key, the extended configuration may end up applied to all files.
527
+
:::
528
+
522
529
#### Using Predefined Configurations
523
530
524
531
ESLint has two predefined configurations for JavaScript:
@@ -535,6 +542,7 @@ import { defineConfig } from "eslint/config";
535
542
536
543
exportdefaultdefineConfig([
537
544
{
545
+
files: ["**/*.js"],
538
546
plugins: {
539
547
js
540
548
},
@@ -561,6 +569,7 @@ import { defineConfig } from "eslint/config";
0 commit comments