Skip to content

Commit 9fe068c

Browse files
authored
docs: how to author plugins with configs that extend other configs (#18753)
* docs: how to author plugins with configs that extend other configs It's not immediately clear from the current documentation how authors should migrate configs that extend other configs. According to the [full documentation][1], an array is actually expected, which isn't clear in the migration documentation. This change updates the documentation to include an array example, and links back to the full documentation. [1]: https://eslint.org/docs/latest/extend/plugins#configs-in-plugins * Review markups - fix quote style - remove stale comment - clarify copy on spreading * Copy tweak
1 parent b97fa05 commit 9fe068c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

docs/src/extend/plugin-migration-flat-config.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,43 @@ export default [
199199
];
200200
```
201201

202+
If your config extends other configs, you can export an array:
203+
204+
```js
205+
const baseConfig = require("./base-config");
206+
207+
module.exports = {
208+
configs: {
209+
extendedConfig: [
210+
baseConfig,
211+
{
212+
rules: {
213+
"example/rule1": "error",
214+
"example/rule2": "error"
215+
}
216+
}
217+
],
218+
},
219+
};
220+
```
221+
202222
You should update your documentation so your plugin users know how to reference the exported configs.
203223

224+
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.
225+
226+
Here's an example with both an object config and an array config:
227+
228+
```js
229+
import example from "eslint-plugin-example";
230+
231+
export default [
232+
example.configs.recommended, // Object, so don't spread
233+
...example.configs.extendedConfig, // Array, so needs spreading
234+
];
235+
```
236+
237+
For more information, see the [full documentation](https://eslint.org/docs/latest/extend/plugins#configs-in-plugins).
238+
204239
## Migrating Environments for Flat Config
205240

206241
Environments are no longer supported in flat config, and so we recommend transitioning your environments into exported configs. For example, suppose you export a `mocha` environment like this:

0 commit comments

Comments
 (0)