Skip to content

Commit 93dbceb

Browse files
authored
Update README.md
The existing code from the docs will result in `Cannot find module 'eslint-plugin-react/configs/recommended'`. Updated the README page with a working example.
1 parent 865ed16 commit 93dbceb

File tree

1 file changed

+21
-44
lines changed

1 file changed

+21
-44
lines changed

README.md

+21-44
Original file line numberDiff line numberDiff line change
@@ -217,66 +217,43 @@ In the new config system, `plugin:` protocol(e.g. `plugin:react/recommended`) is
217217
As eslint does not automatically import the preset config (shareable config), you explicitly do it by yourself.
218218

219219
```js
220-
const reactRecommended = require('eslint-plugin-react/configs/recommended');
221-
222-
module.exports = [
223-
224-
reactRecommended, // This is not a plugin object, but a shareable config object
225-
226-
];
227-
```
228-
229-
You can of course add/override some properties.
230-
231-
**Note**: Our shareable configs does not preconfigure `files` or [`languageOptions.globals`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuration-objects).
232-
For most of the cases, you probably want to configure some properties by yourself.
233-
234-
```js
235-
const reactRecommended = require('eslint-plugin-react/configs/recommended');
220+
const react = require('eslint-plugin-react');
236221
const globals = require('globals');
237222

238223
module.exports = [
239224
225+
'eslint:recommended',
226+
react.configs.recommended, // <-- add the recommended config into the array
240227
{
241-
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
242-
...reactRecommended,
243-
languageOptions: {
244-
...reactRecommended.languageOptions,
245-
globals: {
246-
...globals.serviceworker,
247-
...globals.browser;
248-
},
228+
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
229+
plugins: {
230+
react,
249231
},
250-
},
251-
252-
];
253-
```
254-
255-
The above example is same as the example below, as the new config system is based on chaining.
256-
257-
```js
258-
const reactRecommended = require('eslint-plugin-react/configs/recommended');
259-
const globals = require('globals');
260-
261-
module.exports = [
262-
263-
{
264-
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
265-
...reactRecommended,
266-
},
267-
{
268-
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
269232
languageOptions: {
233+
parserOptions: {
234+
ecmaFeatures: {
235+
jsx: true,
236+
},
237+
},
270238
globals: {
271-
...globals.serviceworker,
272239
...globals.browser,
273240
},
274241
},
242+
rules: {
243+
// ... any rules you want
244+
'react/jsx-uses-react': 'error',
245+
'react/jsx-uses-vars': 'error',
246+
},
247+
// ... others are omitted for brevity
275248
},
276249
277250
];
278251
```
279252

253+
You can of course add/override some properties.
254+
255+
**Note**: Our shareable configs do not preconfigure `files` or [`languageOptions.globals`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuration-objects).
256+
280257
## List of supported rules
281258

282259
<!-- begin auto-generated rules list -->

0 commit comments

Comments
 (0)