Skip to content

Commit 2692c07

Browse files
bradzacherljharb
authored andcommitted
[Fix] export flat configs from plugin root and fix flat config crash
1 parent 393bfa2 commit 2692c07

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

README.md

+9-20
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,16 @@ Refer to the [official docs](https://eslint.org/docs/latest/user-guide/configuri
203203
The schema of the `settings.react` object would be identical to that of what's already described above in the legacy config section.
204204

205205
<!-- markdownlint-disable-next-line no-duplicate-heading -->
206-
### Shareable configs
207-
208-
There're also 3 shareable configs.
209-
210-
- `eslint-plugin-react/configs/all`
211-
- `eslint-plugin-react/configs/recommended`
212-
- `eslint-plugin-react/configs/jsx-runtime`
213-
214-
If your eslint.config.js is ESM, include the `.js` extension (e.g. `eslint-plugin-react/recommended.js`). Note that the next semver-major will require omitting the extension for these imports.
215-
216-
**Note**: These configurations will import `eslint-plugin-react` and enable JSX in [`languageOptions.parserOptions`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuration-objects).
206+
### Flat Configs
217207

218-
In the new config system, `plugin:` protocol(e.g. `plugin:react/recommended`) is no longer valid.
219-
As eslint does not automatically import the preset config (shareable config), you explicitly do it by yourself.
208+
The flat configs are available via the root plugin import. They will configure the plugin under the `react/` namespace and enable JSX in [`languageOptions.parserOptions`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuration-objects).
220209

221210
```js
222-
const reactRecommended = require('eslint-plugin-react/configs/recommended');
211+
const reactPlugin = require('eslint-plugin-react');
223212

224213
module.exports = [
225214
226-
reactRecommended, // This is not a plugin object, but a shareable config object
215+
reactPlugin.configs['flat/recommended'], // This is not a plugin object, but a shareable config object
227216
228217
];
229218
```
@@ -234,16 +223,16 @@ You can of course add/override some properties.
234223
For most of the cases, you probably want to configure some properties by yourself.
235224

236225
```js
237-
const reactRecommended = require('eslint-plugin-react/configs/recommended');
226+
const reactPlugin = require('eslint-plugin-react');
238227
const globals = require('globals');
239228

240229
module.exports = [
241230
242231
{
243232
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
244-
...reactRecommended,
233+
...reactPlugin.configs['flat/recommended'],
245234
languageOptions: {
246-
...reactRecommended.languageOptions,
235+
...reactPlugin.configs['flat/recommended'].languageOptions,
247236
globals: {
248237
...globals.serviceworker,
249238
...globals.browser,
@@ -257,14 +246,14 @@ module.exports = [
257246
The above example is same as the example below, as the new config system is based on chaining.
258247

259248
```js
260-
const reactRecommended = require('eslint-plugin-react/configs/recommended');
249+
const reactPlugin = require('eslint-plugin-react');
261250
const globals = require('globals');
262251

263252
module.exports = [
264253
265254
{
266255
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
267-
...reactRecommended,
256+
...reactPlugin.configs['flat/recommended'],
268257
},
269258
{
270259
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],

index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const plugins = [
1111
'react',
1212
];
1313

14-
module.exports = {
14+
const plugin = {
1515
deprecatedRules: configAll.plugins.react.deprecatedRules,
1616
rules: allRules,
1717
configs: {
@@ -27,5 +27,16 @@ module.exports = {
2727
parserOptions: configRuntime.languageOptions.parserOptions,
2828
plugins,
2929
}),
30+
31+
'flat/recommended': Object.assign({}, configRecommended),
32+
'flat/all': Object.assign({}, configAll),
33+
'flat/jsx-runtime': Object.assign({}, configRuntime),
3034
},
3135
};
36+
37+
// need to ensure the flat configs reference the same plugin identity
38+
plugin.configs['flat/recommended'].plugins.react = plugin;
39+
plugin.configs['flat/all'].plugins.react = plugin;
40+
plugin.configs['flat/recommended'].plugins.react = plugin;
41+
42+
module.exports = plugin;

lib/rules/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* eslint global-require: 0 */
44

5-
/** @type {Record<string, import('eslint').Rule.RuleModule>} */
5+
/** @satisfies {Record<string, import('eslint').Rule.RuleModule>} */
66
module.exports = {
77
'boolean-prop-naming': require('./boolean-prop-naming'),
88
'button-has-type': require('./button-has-type'),

0 commit comments

Comments
 (0)