[d565449] | 1 | # `eslint-plugin-react` <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
---|
| 2 |
|
---|
| 3 | ===================
|
---|
| 4 |
|
---|
| 5 | [![github actions][actions-image]][actions-url]
|
---|
| 6 | [![Maintenance Status][status-image]][status-url]
|
---|
| 7 | [![NPM version][npm-image]][npm-url]
|
---|
| 8 | [![Tidelift][tidelift-image]][tidelift-url]
|
---|
| 9 |
|
---|
| 10 | React specific linting rules for `eslint`
|
---|
| 11 |
|
---|
| 12 | ## Installation
|
---|
| 13 |
|
---|
| 14 | ```sh
|
---|
| 15 | npm install eslint eslint-plugin-react --save-dev
|
---|
| 16 | ```
|
---|
| 17 |
|
---|
| 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 |
|
---|
| 20 | ## Configuration (legacy: `.eslintrc*`) <a id="configuration"></a>
|
---|
| 21 |
|
---|
| 22 | Use [our preset](#recommended) to get reasonable defaults:
|
---|
| 23 |
|
---|
| 24 | ```json
|
---|
| 25 | "extends": [
|
---|
| 26 | "eslint:recommended",
|
---|
| 27 | "plugin:react/recommended"
|
---|
| 28 | ]
|
---|
| 29 | ```
|
---|
| 30 |
|
---|
| 31 | If you are using the [new JSX transform from React 17](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#removing-unused-react-imports), extend [`react/jsx-runtime`](https://github.com/jsx-eslint/eslint-plugin-react/blob/c8917b0885094b5e4cc2a6f613f7fb6f16fe932e/index.js#L163-L176) in your eslint config (add `"plugin:react/jsx-runtime"` to `"extends"`) to disable the relevant rules.
|
---|
| 32 |
|
---|
| 33 | You should also specify settings that will be shared across all the plugin rules. ([More about eslint shared settings](https://eslint.org/docs/user-guide/configuring/configuration-files#adding-shared-settings))
|
---|
| 34 |
|
---|
| 35 | ```json5
|
---|
| 36 | {
|
---|
| 37 | "settings": {
|
---|
| 38 | "react": {
|
---|
| 39 | "createClass": "createReactClass", // Regex for Component Factory to use,
|
---|
| 40 | // default to "createReactClass"
|
---|
| 41 | "pragma": "React", // Pragma to use, default to "React"
|
---|
| 42 | "fragment": "Fragment", // Fragment to use (may be a property of <pragma>), default to "Fragment"
|
---|
| 43 | "version": "detect", // React version. "detect" automatically picks the version you have installed.
|
---|
| 44 | // You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
|
---|
| 45 | // Defaults to the "defaultVersion" setting and warns if missing, and to "detect" in the future
|
---|
| 46 | "defaultVersion": "", // Default React version to use when the version you have installed cannot be detected.
|
---|
| 47 | // If not provided, defaults to the latest React version.
|
---|
| 48 | "flowVersion": "0.53" // Flow version
|
---|
| 49 | },
|
---|
| 50 | "propWrapperFunctions": [
|
---|
| 51 | // The names of any function used to wrap propTypes, e.g. `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped.
|
---|
| 52 | "forbidExtraProps",
|
---|
| 53 | {"property": "freeze", "object": "Object"},
|
---|
| 54 | {"property": "myFavoriteWrapper"},
|
---|
| 55 | // for rules that check exact prop wrappers
|
---|
| 56 | {"property": "forbidExtraProps", "exact": true}
|
---|
| 57 | ],
|
---|
| 58 | "componentWrapperFunctions": [
|
---|
| 59 | // The name of any function used to wrap components, e.g. Mobx `observer` function. If this isn't set, components wrapped by these functions will be skipped.
|
---|
| 60 | "observer", // `property`
|
---|
| 61 | {"property": "styled"}, // `object` is optional
|
---|
| 62 | {"property": "observer", "object": "Mobx"},
|
---|
| 63 | {"property": "observer", "object": "<pragma>"} // sets `object` to whatever value `settings.react.pragma` is set to
|
---|
| 64 | ],
|
---|
| 65 | "formComponents": [
|
---|
| 66 | // Components used as alternatives to <form> for forms, eg. <Form endpoint={ url } />
|
---|
| 67 | "CustomForm",
|
---|
| 68 | {"name": "SimpleForm", "formAttribute": "endpoint"},
|
---|
| 69 | {"name": "Form", "formAttribute": ["registerEndpoint", "loginEndpoint"]}, // allows specifying multiple properties if necessary
|
---|
| 70 | ],
|
---|
| 71 | "linkComponents": [
|
---|
| 72 | // Components used as alternatives to <a> for linking, eg. <Link to={ url } />
|
---|
| 73 | "Hyperlink",
|
---|
| 74 | {"name": "MyLink", "linkAttribute": "to"},
|
---|
| 75 | {"name": "Link", "linkAttribute": ["to", "href"]}, // allows specifying multiple properties if necessary
|
---|
| 76 | ]
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | ```
|
---|
| 80 |
|
---|
| 81 | If you do not use a preset you will need to specify individual rules and add extra configuration.
|
---|
| 82 |
|
---|
| 83 | Add "react" to the plugins section.
|
---|
| 84 |
|
---|
| 85 | ```json
|
---|
| 86 | {
|
---|
| 87 | "plugins": [
|
---|
| 88 | "react"
|
---|
| 89 | ]
|
---|
| 90 | }
|
---|
| 91 | ```
|
---|
| 92 |
|
---|
| 93 | Enable JSX support.
|
---|
| 94 |
|
---|
| 95 | With `eslint` 2+
|
---|
| 96 |
|
---|
| 97 | ```json
|
---|
| 98 | {
|
---|
| 99 | "parserOptions": {
|
---|
| 100 | "ecmaFeatures": {
|
---|
| 101 | "jsx": true
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | ```
|
---|
| 106 |
|
---|
| 107 | Enable the rules that you would like to use.
|
---|
| 108 |
|
---|
| 109 | ```json
|
---|
| 110 | "rules": {
|
---|
| 111 | "react/jsx-uses-react": "error",
|
---|
| 112 | "react/jsx-uses-vars": "error",
|
---|
| 113 | }
|
---|
| 114 | ```
|
---|
| 115 |
|
---|
| 116 | ### Shareable configs
|
---|
| 117 |
|
---|
| 118 | #### Recommended
|
---|
| 119 |
|
---|
| 120 | This plugin exports a `recommended` configuration that enforces React good practices.
|
---|
| 121 |
|
---|
| 122 | To enable this configuration use the `extends` property in your `.eslintrc` config file:
|
---|
| 123 |
|
---|
| 124 | ```json
|
---|
| 125 | {
|
---|
| 126 | "extends": ["eslint:recommended", "plugin:react/recommended"]
|
---|
| 127 | }
|
---|
| 128 | ```
|
---|
| 129 |
|
---|
| 130 | See [`eslint` documentation](https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files) for more information about extending configuration files.
|
---|
| 131 |
|
---|
| 132 | #### All
|
---|
| 133 |
|
---|
| 134 | This plugin also exports an `all` configuration that includes every available rule.
|
---|
| 135 | This pairs well with the `eslint:all` rule.
|
---|
| 136 |
|
---|
| 137 | ```json
|
---|
| 138 | {
|
---|
| 139 | "plugins": [
|
---|
| 140 | "react"
|
---|
| 141 | ],
|
---|
| 142 | "extends": ["eslint:all", "plugin:react/all"]
|
---|
| 143 | }
|
---|
| 144 | ```
|
---|
| 145 |
|
---|
| 146 | **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).
|
---|
| 147 |
|
---|
| 148 | ## Configuration (new: `eslint.config.js`)
|
---|
| 149 |
|
---|
| 150 | From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), eslint announced a new config system.
|
---|
| 151 | In the new system, `.eslintrc*` is no longer used. `eslint.config.js` would be the default config file name.
|
---|
| 152 | In eslint `v8`, the legacy system (`.eslintrc*`) would still be supported, while in eslint `v9`, only the new system would be supported.
|
---|
| 153 |
|
---|
| 154 | And from [`v8.23.0`](https://github.com/eslint/eslint/releases/tag/v8.23.0), eslint CLI starts to look up `eslint.config.js`.
|
---|
| 155 | **So, if your eslint is `>=8.23.0`, you're 100% ready to use the new config system.**
|
---|
| 156 |
|
---|
| 157 | You might want to check out the official blog posts,
|
---|
| 158 |
|
---|
| 159 | - <https://eslint.org/blog/2022/08/new-config-system-part-1/>
|
---|
| 160 | - <https://eslint.org/blog/2022/08/new-config-system-part-2/>
|
---|
| 161 | - <https://eslint.org/blog/2022/08/new-config-system-part-3/>
|
---|
| 162 |
|
---|
| 163 | and the [official docs](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new).
|
---|
| 164 |
|
---|
| 165 | ### Plugin
|
---|
| 166 |
|
---|
| 167 | The default export of `eslint-plugin-react` is a plugin object.
|
---|
| 168 |
|
---|
| 169 | ```js
|
---|
| 170 | const react = require('eslint-plugin-react');
|
---|
| 171 | const globals = require('globals');
|
---|
| 172 |
|
---|
| 173 | module.exports = [
|
---|
| 174 | …
|
---|
| 175 | {
|
---|
| 176 | files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
|
---|
| 177 | plugins: {
|
---|
| 178 | react,
|
---|
| 179 | },
|
---|
| 180 | languageOptions: {
|
---|
| 181 | parserOptions: {
|
---|
| 182 | ecmaFeatures: {
|
---|
| 183 | jsx: true,
|
---|
| 184 | },
|
---|
| 185 | },
|
---|
| 186 | globals: {
|
---|
| 187 | ...globals.browser,
|
---|
| 188 | },
|
---|
| 189 | },
|
---|
| 190 | rules: {
|
---|
| 191 | // ... any rules you want
|
---|
| 192 | 'react/jsx-uses-react': 'error',
|
---|
| 193 | 'react/jsx-uses-vars': 'error',
|
---|
| 194 | },
|
---|
| 195 | // ... others are omitted for brevity
|
---|
| 196 | },
|
---|
| 197 | …
|
---|
| 198 | ];
|
---|
| 199 | ```
|
---|
| 200 |
|
---|
| 201 | ### Configuring shared settings
|
---|
| 202 |
|
---|
| 203 | Refer to the [official docs](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuring-shared-settings).
|
---|
| 204 |
|
---|
| 205 | The schema of the `settings.react` object would be identical to that of what's already described above in the legacy config section.
|
---|
| 206 |
|
---|
| 207 | <!-- markdownlint-disable-next-line no-duplicate-heading -->
|
---|
| 208 | ### Flat Configs
|
---|
| 209 |
|
---|
| 210 | This plugin exports 3 flat configs:
|
---|
| 211 |
|
---|
| 212 | - `flat.all`
|
---|
| 213 | - `flat.recommended`
|
---|
| 214 | - `flat['jsx-runtime']`
|
---|
| 215 |
|
---|
| 216 | 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/use/configure/language-options#specifying-parser-options).
|
---|
| 217 |
|
---|
| 218 | ```js
|
---|
| 219 | const reactPlugin = require('eslint-plugin-react');
|
---|
| 220 |
|
---|
| 221 | module.exports = [
|
---|
| 222 | …
|
---|
| 223 | reactPlugin.configs.flat.recommended, // This is not a plugin object, but a shareable config object
|
---|
| 224 | …
|
---|
| 225 | ];
|
---|
| 226 | ```
|
---|
| 227 |
|
---|
| 228 | You can of course add/override some properties.
|
---|
| 229 |
|
---|
| 230 | **Note**: Our shareable configs does not preconfigure `files` or [`languageOptions.globals`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuration-objects).
|
---|
| 231 | For most of the cases, you probably want to configure some properties by yourself.
|
---|
| 232 |
|
---|
| 233 | ```js
|
---|
| 234 | const reactPlugin = require('eslint-plugin-react');
|
---|
| 235 | const globals = require('globals');
|
---|
| 236 |
|
---|
| 237 | module.exports = [
|
---|
| 238 | …
|
---|
| 239 | {
|
---|
| 240 | files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
|
---|
| 241 | ...reactPlugin.configs.flat.recommended,
|
---|
| 242 | languageOptions: {
|
---|
| 243 | ...reactPlugin.configs.flat.recommended.languageOptions,
|
---|
| 244 | globals: {
|
---|
| 245 | ...globals.serviceworker,
|
---|
| 246 | ...globals.browser,
|
---|
| 247 | },
|
---|
| 248 | },
|
---|
| 249 | },
|
---|
| 250 | …
|
---|
| 251 | ];
|
---|
| 252 | ```
|
---|
| 253 |
|
---|
| 254 | The above example is same as the example below, as the new config system is based on chaining.
|
---|
| 255 |
|
---|
| 256 | ```js
|
---|
| 257 | const reactPlugin = require('eslint-plugin-react');
|
---|
| 258 | const globals = require('globals');
|
---|
| 259 |
|
---|
| 260 | module.exports = [
|
---|
| 261 | …
|
---|
| 262 | {
|
---|
| 263 | files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
|
---|
| 264 | ...reactPlugin.configs.flat.recommended,
|
---|
| 265 | },
|
---|
| 266 | {
|
---|
| 267 | files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
|
---|
| 268 | languageOptions: {
|
---|
| 269 | globals: {
|
---|
| 270 | ...globals.serviceworker,
|
---|
| 271 | ...globals.browser,
|
---|
| 272 | },
|
---|
| 273 | },
|
---|
| 274 | },
|
---|
| 275 | …
|
---|
| 276 | ];
|
---|
| 277 | ```
|
---|
| 278 |
|
---|
| 279 | ## List of supported rules
|
---|
| 280 |
|
---|
| 281 | <!-- begin auto-generated rules list -->
|
---|
| 282 |
|
---|
| 283 | 💼 [Configurations](https://github.com/jsx-eslint/eslint-plugin-react/#shareable-configs) enabled in.\
|
---|
| 284 | 🚫 [Configurations](https://github.com/jsx-eslint/eslint-plugin-react/#shareable-configs) disabled in.\
|
---|
| 285 | 🏃 Set in the `jsx-runtime` [configuration](https://github.com/jsx-eslint/eslint-plugin-react/#shareable-configs).\
|
---|
| 286 | ☑️ Set in the `recommended` [configuration](https://github.com/jsx-eslint/eslint-plugin-react/#shareable-configs).\
|
---|
| 287 | 🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
---|
| 288 | 💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\
|
---|
| 289 | ❌ Deprecated.
|
---|
| 290 |
|
---|
| 291 | | Name | Description | 💼 | 🚫 | 🔧 | 💡 | ❌ |
|
---|
| 292 | | :------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------- | :- | :- | :- | :- | :- |
|
---|
| 293 | | [boolean-prop-naming](docs/rules/boolean-prop-naming.md) | Enforces consistent naming for boolean props | | | | | |
|
---|
| 294 | | [button-has-type](docs/rules/button-has-type.md) | Disallow usage of `button` elements without an explicit `type` attribute | | | | | |
|
---|
| 295 | | [checked-requires-onchange-or-readonly](docs/rules/checked-requires-onchange-or-readonly.md) | Enforce using `onChange` or `readonly` attribute when `checked` is used | | | | | |
|
---|
| 296 | | [default-props-match-prop-types](docs/rules/default-props-match-prop-types.md) | Enforce all defaultProps have a corresponding non-required PropType | | | | | |
|
---|
| 297 | | [destructuring-assignment](docs/rules/destructuring-assignment.md) | Enforce consistent usage of destructuring assignment of props, state, and context | | | 🔧 | | |
|
---|
| 298 | | [display-name](docs/rules/display-name.md) | Disallow missing displayName in a React component definition | ☑️ | | | | |
|
---|
| 299 | | [forbid-component-props](docs/rules/forbid-component-props.md) | Disallow certain props on components | | | | | |
|
---|
| 300 | | [forbid-dom-props](docs/rules/forbid-dom-props.md) | Disallow certain props on DOM Nodes | | | | | |
|
---|
| 301 | | [forbid-elements](docs/rules/forbid-elements.md) | Disallow certain elements | | | | | |
|
---|
| 302 | | [forbid-foreign-prop-types](docs/rules/forbid-foreign-prop-types.md) | Disallow using another component's propTypes | | | | | |
|
---|
| 303 | | [forbid-prop-types](docs/rules/forbid-prop-types.md) | Disallow certain propTypes | | | | | |
|
---|
| 304 | | [function-component-definition](docs/rules/function-component-definition.md) | Enforce a specific function type for function components | | | 🔧 | | |
|
---|
| 305 | | [hook-use-state](docs/rules/hook-use-state.md) | Ensure destructuring and symmetric naming of useState hook value and setter variables | | | | 💡 | |
|
---|
| 306 | | [iframe-missing-sandbox](docs/rules/iframe-missing-sandbox.md) | Enforce sandbox attribute on iframe elements | | | | | |
|
---|
| 307 | | [jsx-boolean-value](docs/rules/jsx-boolean-value.md) | Enforce boolean attributes notation in JSX | | | 🔧 | | |
|
---|
| 308 | | [jsx-child-element-spacing](docs/rules/jsx-child-element-spacing.md) | Enforce or disallow spaces inside of curly braces in JSX attributes and expressions | | | | | |
|
---|
| 309 | | [jsx-closing-bracket-location](docs/rules/jsx-closing-bracket-location.md) | Enforce closing bracket location in JSX | | | 🔧 | | |
|
---|
| 310 | | [jsx-closing-tag-location](docs/rules/jsx-closing-tag-location.md) | Enforce closing tag location for multiline JSX | | | 🔧 | | |
|
---|
| 311 | | [jsx-curly-brace-presence](docs/rules/jsx-curly-brace-presence.md) | Disallow unnecessary JSX expressions when literals alone are sufficient or enforce JSX expressions on literals in JSX children or attributes | | | 🔧 | | |
|
---|
| 312 | | [jsx-curly-newline](docs/rules/jsx-curly-newline.md) | Enforce consistent linebreaks in curly braces in JSX attributes and expressions | | | 🔧 | | |
|
---|
| 313 | | [jsx-curly-spacing](docs/rules/jsx-curly-spacing.md) | Enforce or disallow spaces inside of curly braces in JSX attributes and expressions | | | 🔧 | | |
|
---|
| 314 | | [jsx-equals-spacing](docs/rules/jsx-equals-spacing.md) | Enforce or disallow spaces around equal signs in JSX attributes | | | 🔧 | | |
|
---|
| 315 | | [jsx-filename-extension](docs/rules/jsx-filename-extension.md) | Disallow file extensions that may contain JSX | | | | | |
|
---|
| 316 | | [jsx-first-prop-new-line](docs/rules/jsx-first-prop-new-line.md) | Enforce proper position of the first property in JSX | | | 🔧 | | |
|
---|
| 317 | | [jsx-fragments](docs/rules/jsx-fragments.md) | Enforce shorthand or standard form for React fragments | | | 🔧 | | |
|
---|
| 318 | | [jsx-handler-names](docs/rules/jsx-handler-names.md) | Enforce event handler naming conventions in JSX | | | | | |
|
---|
| 319 | | [jsx-indent](docs/rules/jsx-indent.md) | Enforce JSX indentation | | | 🔧 | | |
|
---|
| 320 | | [jsx-indent-props](docs/rules/jsx-indent-props.md) | Enforce props indentation in JSX | | | 🔧 | | |
|
---|
| 321 | | [jsx-key](docs/rules/jsx-key.md) | Disallow missing `key` props in iterators/collection literals | ☑️ | | | | |
|
---|
| 322 | | [jsx-max-depth](docs/rules/jsx-max-depth.md) | Enforce JSX maximum depth | | | | | |
|
---|
| 323 | | [jsx-max-props-per-line](docs/rules/jsx-max-props-per-line.md) | Enforce maximum of props on a single line in JSX | | | 🔧 | | |
|
---|
| 324 | | [jsx-newline](docs/rules/jsx-newline.md) | Require or prevent a new line after jsx elements and expressions. | | | 🔧 | | |
|
---|
| 325 | | [jsx-no-bind](docs/rules/jsx-no-bind.md) | Disallow `.bind()` or arrow functions in JSX props | | | | | |
|
---|
| 326 | | [jsx-no-comment-textnodes](docs/rules/jsx-no-comment-textnodes.md) | Disallow comments from being inserted as text nodes | ☑️ | | | | |
|
---|
| 327 | | [jsx-no-constructed-context-values](docs/rules/jsx-no-constructed-context-values.md) | Disallows JSX context provider values from taking values that will cause needless rerenders | | | | | |
|
---|
| 328 | | [jsx-no-duplicate-props](docs/rules/jsx-no-duplicate-props.md) | Disallow duplicate properties in JSX | ☑️ | | | | |
|
---|
| 329 | | [jsx-no-leaked-render](docs/rules/jsx-no-leaked-render.md) | Disallow problematic leaked values from being rendered | | | 🔧 | | |
|
---|
| 330 | | [jsx-no-literals](docs/rules/jsx-no-literals.md) | Disallow usage of string literals in JSX | | | | | |
|
---|
| 331 | | [jsx-no-script-url](docs/rules/jsx-no-script-url.md) | Disallow usage of `javascript:` URLs | | | | | |
|
---|
| 332 | | [jsx-no-target-blank](docs/rules/jsx-no-target-blank.md) | Disallow `target="_blank"` attribute without `rel="noreferrer"` | ☑️ | | 🔧 | | |
|
---|
| 333 | | [jsx-no-undef](docs/rules/jsx-no-undef.md) | Disallow undeclared variables in JSX | ☑️ | | | | |
|
---|
| 334 | | [jsx-no-useless-fragment](docs/rules/jsx-no-useless-fragment.md) | Disallow unnecessary fragments | | | 🔧 | | |
|
---|
| 335 | | [jsx-one-expression-per-line](docs/rules/jsx-one-expression-per-line.md) | Require one JSX element per line | | | 🔧 | | |
|
---|
| 336 | | [jsx-pascal-case](docs/rules/jsx-pascal-case.md) | Enforce PascalCase for user-defined JSX components | | | | | |
|
---|
| 337 | | [jsx-props-no-multi-spaces](docs/rules/jsx-props-no-multi-spaces.md) | Disallow multiple spaces between inline JSX props | | | 🔧 | | |
|
---|
| 338 | | [jsx-props-no-spread-multi](docs/rules/jsx-props-no-spread-multi.md) | Disallow JSX prop spreading the same identifier multiple times | | | | | |
|
---|
| 339 | | [jsx-props-no-spreading](docs/rules/jsx-props-no-spreading.md) | Disallow JSX prop spreading | | | | | |
|
---|
| 340 | | [jsx-sort-default-props](docs/rules/jsx-sort-default-props.md) | Enforce defaultProps declarations alphabetical sorting | | | | | ❌ |
|
---|
| 341 | | [jsx-sort-props](docs/rules/jsx-sort-props.md) | Enforce props alphabetical sorting | | | 🔧 | | |
|
---|
| 342 | | [jsx-space-before-closing](docs/rules/jsx-space-before-closing.md) | Enforce spacing before closing bracket in JSX | | | 🔧 | | ❌ |
|
---|
| 343 | | [jsx-tag-spacing](docs/rules/jsx-tag-spacing.md) | Enforce whitespace in and around the JSX opening and closing brackets | | | 🔧 | | |
|
---|
| 344 | | [jsx-uses-react](docs/rules/jsx-uses-react.md) | Disallow React to be incorrectly marked as unused | ☑️ | 🏃 | | | |
|
---|
| 345 | | [jsx-uses-vars](docs/rules/jsx-uses-vars.md) | Disallow variables used in JSX to be incorrectly marked as unused | ☑️ | | | | |
|
---|
| 346 | | [jsx-wrap-multilines](docs/rules/jsx-wrap-multilines.md) | Disallow missing parentheses around multiline JSX | | | 🔧 | | |
|
---|
| 347 | | [no-access-state-in-setstate](docs/rules/no-access-state-in-setstate.md) | Disallow when this.state is accessed within setState | | | | | |
|
---|
| 348 | | [no-adjacent-inline-elements](docs/rules/no-adjacent-inline-elements.md) | Disallow adjacent inline elements not separated by whitespace. | | | | | |
|
---|
| 349 | | [no-array-index-key](docs/rules/no-array-index-key.md) | Disallow usage of Array index in keys | | | | | |
|
---|
| 350 | | [no-arrow-function-lifecycle](docs/rules/no-arrow-function-lifecycle.md) | Lifecycle methods should be methods on the prototype, not class fields | | | 🔧 | | |
|
---|
| 351 | | [no-children-prop](docs/rules/no-children-prop.md) | Disallow passing of children as props | ☑️ | | | | |
|
---|
| 352 | | [no-danger](docs/rules/no-danger.md) | Disallow usage of dangerous JSX properties | | | | | |
|
---|
| 353 | | [no-danger-with-children](docs/rules/no-danger-with-children.md) | Disallow when a DOM element is using both children and dangerouslySetInnerHTML | ☑️ | | | | |
|
---|
| 354 | | [no-deprecated](docs/rules/no-deprecated.md) | Disallow usage of deprecated methods | ☑️ | | | | |
|
---|
| 355 | | [no-did-mount-set-state](docs/rules/no-did-mount-set-state.md) | Disallow usage of setState in componentDidMount | | | | | |
|
---|
| 356 | | [no-did-update-set-state](docs/rules/no-did-update-set-state.md) | Disallow usage of setState in componentDidUpdate | | | | | |
|
---|
| 357 | | [no-direct-mutation-state](docs/rules/no-direct-mutation-state.md) | Disallow direct mutation of this.state | ☑️ | | | | |
|
---|
| 358 | | [no-find-dom-node](docs/rules/no-find-dom-node.md) | Disallow usage of findDOMNode | ☑️ | | | | |
|
---|
| 359 | | [no-invalid-html-attribute](docs/rules/no-invalid-html-attribute.md) | Disallow usage of invalid attributes | | | | 💡 | |
|
---|
| 360 | | [no-is-mounted](docs/rules/no-is-mounted.md) | Disallow usage of isMounted | ☑️ | | | | |
|
---|
| 361 | | [no-multi-comp](docs/rules/no-multi-comp.md) | Disallow multiple component definition per file | | | | | |
|
---|
| 362 | | [no-namespace](docs/rules/no-namespace.md) | Enforce that namespaces are not used in React elements | | | | | |
|
---|
| 363 | | [no-object-type-as-default-prop](docs/rules/no-object-type-as-default-prop.md) | Disallow usage of referential-type variables as default param in functional component | | | | | |
|
---|
| 364 | | [no-redundant-should-component-update](docs/rules/no-redundant-should-component-update.md) | Disallow usage of shouldComponentUpdate when extending React.PureComponent | | | | | |
|
---|
| 365 | | [no-render-return-value](docs/rules/no-render-return-value.md) | Disallow usage of the return value of ReactDOM.render | ☑️ | | | | |
|
---|
| 366 | | [no-set-state](docs/rules/no-set-state.md) | Disallow usage of setState | | | | | |
|
---|
| 367 | | [no-string-refs](docs/rules/no-string-refs.md) | Disallow using string references | ☑️ | | | | |
|
---|
| 368 | | [no-this-in-sfc](docs/rules/no-this-in-sfc.md) | Disallow `this` from being used in stateless functional components | | | | | |
|
---|
| 369 | | [no-typos](docs/rules/no-typos.md) | Disallow common typos | | | | | |
|
---|
| 370 | | [no-unescaped-entities](docs/rules/no-unescaped-entities.md) | Disallow unescaped HTML entities from appearing in markup | ☑️ | | | | |
|
---|
| 371 | | [no-unknown-property](docs/rules/no-unknown-property.md) | Disallow usage of unknown DOM property | ☑️ | | 🔧 | | |
|
---|
| 372 | | [no-unsafe](docs/rules/no-unsafe.md) | Disallow usage of unsafe lifecycle methods | | ☑️ | | | |
|
---|
| 373 | | [no-unstable-nested-components](docs/rules/no-unstable-nested-components.md) | Disallow creating unstable components inside components | | | | | |
|
---|
| 374 | | [no-unused-class-component-methods](docs/rules/no-unused-class-component-methods.md) | Disallow declaring unused methods of component class | | | | | |
|
---|
| 375 | | [no-unused-prop-types](docs/rules/no-unused-prop-types.md) | Disallow definitions of unused propTypes | | | | | |
|
---|
| 376 | | [no-unused-state](docs/rules/no-unused-state.md) | Disallow definitions of unused state | | | | | |
|
---|
| 377 | | [no-will-update-set-state](docs/rules/no-will-update-set-state.md) | Disallow usage of setState in componentWillUpdate | | | | | |
|
---|
| 378 | | [prefer-es6-class](docs/rules/prefer-es6-class.md) | Enforce ES5 or ES6 class for React Components | | | | | |
|
---|
| 379 | | [prefer-exact-props](docs/rules/prefer-exact-props.md) | Prefer exact proptype definitions | | | | | |
|
---|
| 380 | | [prefer-read-only-props](docs/rules/prefer-read-only-props.md) | Enforce that props are read-only | | | 🔧 | | |
|
---|
| 381 | | [prefer-stateless-function](docs/rules/prefer-stateless-function.md) | Enforce stateless components to be written as a pure function | | | | | |
|
---|
| 382 | | [prop-types](docs/rules/prop-types.md) | Disallow missing props validation in a React component definition | ☑️ | | | | |
|
---|
| 383 | | [react-in-jsx-scope](docs/rules/react-in-jsx-scope.md) | Disallow missing React when using JSX | ☑️ | 🏃 | | | |
|
---|
| 384 | | [require-default-props](docs/rules/require-default-props.md) | Enforce a defaultProps definition for every prop that is not a required prop | | | | | |
|
---|
| 385 | | [require-optimization](docs/rules/require-optimization.md) | Enforce React components to have a shouldComponentUpdate method | | | | | |
|
---|
| 386 | | [require-render-return](docs/rules/require-render-return.md) | Enforce ES5 or ES6 class for returning value in render function | ☑️ | | | | |
|
---|
| 387 | | [self-closing-comp](docs/rules/self-closing-comp.md) | Disallow extra closing tags for components without children | | | 🔧 | | |
|
---|
| 388 | | [sort-comp](docs/rules/sort-comp.md) | Enforce component methods order | | | | | |
|
---|
| 389 | | [sort-default-props](docs/rules/sort-default-props.md) | Enforce defaultProps declarations alphabetical sorting | | | | | |
|
---|
| 390 | | [sort-prop-types](docs/rules/sort-prop-types.md) | Enforce propTypes declarations alphabetical sorting | | | 🔧 | | |
|
---|
| 391 | | [state-in-constructor](docs/rules/state-in-constructor.md) | Enforce class component state initialization style | | | | | |
|
---|
| 392 | | [static-property-placement](docs/rules/static-property-placement.md) | Enforces where React component static properties should be positioned. | | | | | |
|
---|
| 393 | | [style-prop-object](docs/rules/style-prop-object.md) | Enforce style prop value is an object | | | | | |
|
---|
| 394 | | [void-dom-elements-no-children](docs/rules/void-dom-elements-no-children.md) | Disallow void DOM elements (e.g. `<img />`, `<br />`) from receiving children | | | | | |
|
---|
| 395 |
|
---|
| 396 | <!-- end auto-generated rules list -->
|
---|
| 397 |
|
---|
| 398 | ## Other useful plugins
|
---|
| 399 |
|
---|
| 400 | - Rules of Hooks: [eslint-plugin-react-hooks](https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks)
|
---|
| 401 | - JSX accessibility: [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)
|
---|
| 402 | - React Native: [eslint-plugin-react-native](https://github.com/Intellicode/eslint-plugin-react-native)
|
---|
| 403 |
|
---|
| 404 | ## License
|
---|
| 405 |
|
---|
| 406 | `eslint-plugin-react` is licensed under the [MIT License](https://opensource.org/licenses/mit-license.php).
|
---|
| 407 |
|
---|
| 408 | [npm-url]: https://npmjs.org/package/eslint-plugin-react
|
---|
| 409 | [npm-image]: https://img.shields.io/npm/v/eslint-plugin-react.svg
|
---|
| 410 |
|
---|
| 411 | [status-url]: https://github.com/jsx-eslint/eslint-plugin-react/pulse
|
---|
| 412 | [status-image]: https://img.shields.io/github/last-commit/jsx-eslint/eslint-plugin-react.svg
|
---|
| 413 |
|
---|
| 414 | [tidelift-url]: https://tidelift.com/subscription/pkg/npm-eslint-plugin-react?utm_source=npm-eslint-plugin-react&utm_medium=referral&utm_campaign=readme
|
---|
| 415 | [tidelift-image]: https://tidelift.com/badges/package/npm/eslint-plugin-react?style=flat
|
---|
| 416 |
|
---|
| 417 | [package-url]: https://npmjs.org/package/eslint-plugin-react
|
---|
| 418 | [npm-version-svg]: https://versionbadg.es/jsx-eslint/eslint-plugin-react.svg
|
---|
| 419 |
|
---|
| 420 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/jsx-eslint/eslint-plugin-react
|
---|
| 421 | [actions-url]: https://github.com/jsx-eslint/eslint-plugin-react/actions
|
---|