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
@@ -15,9 +15,9 @@ React specific linting rules for `eslint`
15
15
npm install eslint eslint-plugin-react --save-dev
16
16
```
17
17
18
-
It is also possible to install ESLint globally rather than locally (using npm install eslint --global). However, this is not recommended, and any plugins or shareable configs that you use must be installed locally in either case.
18
+
It is also possible to install ESLint globally rather than locally (using `npm install -g eslint`). However, this is not recommended, and any plugins or shareable configs that you use must be installed locally in either case.
19
19
20
-
## Configuration
20
+
## Configuration (legacy: `.eslintrc*`)
21
21
22
22
Use [our preset](#recommended) to get reasonable defaults:
23
23
@@ -109,6 +109,174 @@ Enable the rules that you would like to use.
109
109
}
110
110
```
111
111
112
+
### Shareable configs
113
+
114
+
#### Recommended
115
+
116
+
This plugin exports a `recommended` configuration that enforces React good practices.
117
+
118
+
To enable this configuration use the `extends` property in your `.eslintrc` config file:
See [`eslint` documentation](https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files) for more information about extending configuration files.
127
+
128
+
#### All
129
+
130
+
This plugin also exports an `all` configuration that includes every available rule.
131
+
This pairs well with the `eslint:all` rule.
132
+
133
+
```json
134
+
{
135
+
"plugins": [
136
+
"react"
137
+
],
138
+
"extends": ["eslint:all", "plugin:react/all"]
139
+
}
140
+
```
141
+
142
+
**Note**: These configurations will import `eslint-plugin-react` and enable JSX in [parser options](https://eslint.org/docs/user-guide/configuring/language-options#specifying-parser-options).
143
+
144
+
## Configuration (new: `eslint.config.js`)
145
+
146
+
From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), eslint announced a new config system.
147
+
In the new system, `.eslintrc*` is no longer used. `eslint.config.js` would be the default config file name.
148
+
In eslint `v8`, the legacy system (`.eslintrc*`) would still be supported, while in eslint `v9`, only the new system would be supported.
149
+
150
+
And from [`v8.23.0`](https://github.com/eslint/eslint/releases/tag/v8.23.0), eslint CLI starts to look up `eslint.config.js`.
151
+
**So, if your eslint is `>=8.23.0`, you're 100% ready to use the new config system.**
152
+
153
+
You might want to check out the official blog posts,
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.
213
+
214
+
**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).
215
+
216
+
In the new config system, `plugin:` protocol(e.g. `plugin:react/recommended`) is no longer valid.
217
+
As eslint does not automatically import the preset config (shareable config), you explicitly do it by yourself.
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.
||||[react/state-in-constructor](docs/rules/state-in-constructor.md)| Enforce class component state initialization style |
177
346
||||[react/static-property-placement](docs/rules/static-property-placement.md)| Enforces where React component static properties should be positioned. |
@@ -216,7 +385,7 @@ Enable the rules that you would like to use.
216
385
||||[react/jsx-pascal-case](docs/rules/jsx-pascal-case.md)| Enforce PascalCase for user-defined JSX components |
|| 🔧 ||[react/jsx-space-before-closing](docs/rules/jsx-space-before-closing.md)| Enforce spacing before closing bracket in JSX. ❌ This rule is deprecated. |
222
391
|| 🔧 ||[react/jsx-tag-spacing](docs/rules/jsx-tag-spacing.md)| Enforce whitespace in and around the JSX opening and closing brackets |
@@ -225,44 +394,12 @@ Enable the rules that you would like to use.
225
394
|| 🔧 ||[react/jsx-wrap-multilines](docs/rules/jsx-wrap-multilines.md)| Disallow missing parentheses around multiline JSX |
226
395
<!-- AUTO-GENERATED-CONTENT:END -->
227
396
228
-
###Other useful plugins
397
+
## Other useful plugins
229
398
230
399
- Rules of Hooks: [eslint-plugin-react-hooks](https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks)
See [`eslint` documentation](https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files) for more information about extending configuration files.
249
-
250
-
### All
251
-
252
-
This plugin also exports an `all` configuration that includes every available rule.
253
-
This pairs well with the `eslint:all` rule.
254
-
255
-
```json
256
-
{
257
-
"plugins": [
258
-
"react"
259
-
],
260
-
"extends": ["eslint:all", "plugin:react/all"]
261
-
}
262
-
```
263
-
264
-
**Note**: These configurations will import `eslint-plugin-react` and enable JSX in [parser options](https://eslint.org/docs/user-guide/configuring/language-options#specifying-parser-options).
265
-
266
403
## License
267
404
268
405
`eslint-plugin-react` is licensed under the [MIT License](https://opensource.org/licenses/mit-license.php).
0 commit comments