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/plugins.md
+71-4Lines changed: 71 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -260,10 +260,6 @@ module.exports = plugin;
260
260
261
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.
262
262
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
263
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:
Plugins cannot force a specific configuration to be used. Users must manually include a plugin's configurations in their configuration file.
287
283
:::
288
284
285
+
#### Backwards Compatibility for Legacy Configs
286
+
287
+
If your plugin needs to export configs that work both with the current (flat config) system and the old (eslintrc) system, you can export both config types from 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.
288
+
289
+
If you're working on a plugin that has existed prior to ESLint v9.0.0, then you may already have legacy configs with names such as `"recommended"`. If you don't want to update the config name, you can also create an additional entry in the `configs` object prefixed with `"flat/"` (for example, `"flat/recommended"`). Here's an example:
290
+
291
+
```js
292
+
constplugin= {
293
+
meta: {
294
+
name:"eslint-plugin-example",
295
+
version:"1.2.3"
296
+
},
297
+
configs: {},
298
+
rules: {
299
+
"dollar-sign": {
300
+
create(context) {
301
+
// rule implementation ...
302
+
}
303
+
}
304
+
}
305
+
};
306
+
307
+
// assign configs here so we can reference `plugin`
308
+
Object.assign(plugin.configs, {
309
+
310
+
// flat config format
311
+
"flat/recommended": [{
312
+
plugins: {
313
+
example: plugin
314
+
},
315
+
rules: {
316
+
"example/dollar-sign":"error"
317
+
},
318
+
languageOptions: {
319
+
globals: {
320
+
myGlobal:"readonly"
321
+
},
322
+
parserOptions: {
323
+
ecmaFeatures: {
324
+
jsx:true
325
+
}
326
+
}
327
+
}
328
+
}],
329
+
330
+
// eslintrc format
331
+
recommended: {
332
+
plugins: ["example"],
333
+
rules: {
334
+
"example/dollar-sign":"error"
335
+
},
336
+
globals: {
337
+
myGlobal:"readonly"
338
+
},
339
+
parserOptions: {
340
+
ecmaFeatures: {
341
+
jsx:true
342
+
}
343
+
}
344
+
}
345
+
});
346
+
347
+
// for ESM
348
+
exportdefaultplugin;
349
+
350
+
// OR for CommonJS
351
+
module.exports= plugin;
352
+
```
353
+
354
+
With this approach, both configuration systems recognize `"recommended"`. The old config system uses the `recommended` key while the current config system uses the `flat/recommended` key. The `defineConfig()` helper first looks at the `recommended` key, and if that is not in the correct format, it looks for the `flat/recommended` key. This allows you an upgrade path if you'd later like to rename `flat/recommended` to `recommended` when you no longer need to support the old config system.
355
+
289
356
## Testing a Plugin
290
357
291
358
ESLint provides the [`RuleTester`](../integrate/nodejs-api#ruletester) utility to make it easy to test the rules of your plugin.
0 commit comments