eslint-plugin-react. These rules are only active when you extend eslint-config-airbnb (not eslint-config-airbnb-base).
Source: eslint-config-airbnb/rules/react
no-underscore-dangle is extended to allow __REDUX_DEVTOOLS_EXTENSION_COMPOSE__, and class-methods-use-this is configured to exempt all React lifecycle methods.JSX formatting
jsx-quotes — require double quotes in JSX attributes
jsx-quotes — require double quotes in JSX attributes
react/jsx-indent — 2-space indentation in JSX
react/jsx-indent — 2-space indentation in JSX
react/jsx-indent-props — 2-space indentation for props
react/jsx-indent-props — 2-space indentation for props
react/jsx-closing-bracket-location — align closing bracket with opening tag
react/jsx-closing-bracket-location — align closing bracket with opening tag
line-aligned)The closing /> or > of a multiline JSX element must align with the line that contains the opening tag.react/jsx-closing-tag-location — align closing tag with opening tag
react/jsx-closing-tag-location — align closing tag with opening tag
react/jsx-curly-spacing — no spaces inside JSX curly braces
react/jsx-curly-spacing — no spaces inside JSX curly braces
never)react/jsx-equals-spacing — no spaces around JSX attribute equals
react/jsx-equals-spacing — no spaces around JSX attribute equals
never)react/jsx-tag-spacing — consistent whitespace in JSX tags
react/jsx-tag-spacing — consistent whitespace in JSX tags
react/jsx-wrap-multilines — wrap multiline JSX in parentheses
react/jsx-wrap-multilines — wrap multiline JSX in parentheses
react/jsx-first-prop-new-line — first prop on a new line in multiline elements
react/jsx-first-prop-new-line — first prop on a new line in multiline elements
multiline-multiprop)When a JSX element has multiple props and spans multiple lines, the first prop must be on a new line.react/jsx-max-props-per-line — one prop per line in multiline elements
react/jsx-max-props-per-line — one prop per line in multiline elements
react/jsx-one-expression-per-line — one expression per line
react/jsx-one-expression-per-line — one expression per line
react/jsx-curly-brace-presence — disallow unnecessary curly braces
react/jsx-curly-brace-presence — disallow unnecessary curly braces
never for props and children)Do not use curly braces around string literals in props or children when they are not needed.Component structure
react/prefer-stateless-function — prefer function components over class components
react/prefer-stateless-function — prefer function components over class components
React.PureComponent) are exempt.react/prefer-es6-class — require ES6 classes for class components
react/prefer-es6-class — require ES6 classes for class components
class syntax rather than React.createClass.react/function-component-definition — enforce function declaration style
react/function-component-definition — enforce function declaration style
function declarations or function expressions. Unnamed components must use function expressions.react/sort-comp — enforce component method order
react/sort-comp — enforce component method order
- Static variables
- Static methods
- Instance variables
- Lifecycle methods
- Event handlers (
handle*,on*) - Getters and setters
- Other instance methods
- Render helpers (
render*) render
react/state-in-constructor — initialize state in constructor
react/state-in-constructor — initialize state in constructor
react/static-property-placement — static properties as property assignments
react/static-property-placement — static properties as property assignments
defaultProps, propTypes, displayName) must be declared as property assignments after the class definition, not as static class fields.react/destructuring-assignment — always destructure props and state
react/destructuring-assignment — always destructure props and state
always)Props and state must always be destructured before use.Props and prop types
react/prop-types — require prop type definitions
react/prop-types — require prop type definitions
propTypes. This catches typos and documents component contracts.react/require-default-props — require defaultProps for non-required props
react/require-default-props — require defaultProps for non-required props
propTypes must have a corresponding entry in defaultProps.react/default-props-match-prop-types — defaultProps must match propTypes
react/default-props-match-prop-types — defaultProps must match propTypes
defaultProps must correspond to a non-required prop in propTypes.react/forbid-prop-types — disallow loose prop types
react/forbid-prop-types — disallow loose prop types
any, array, object. Use more specific shapes instead.react/no-unused-prop-types — disallow unused prop type definitions
react/no-unused-prop-types — disallow unused prop type definitions
react/jsx-props-no-spreading — disallow JSX prop spreading
react/jsx-props-no-spreading — disallow JSX prop spreading
explicitSpread: 'ignore' allows controlled spreading.react/prefer-exact-props — require exact prop definitions
react/prefer-exact-props — require exact prop definitions
Safety and correctness
react/no-deprecated — disallow deprecated React APIs
react/no-deprecated — disallow deprecated React APIs
componentWillMount and findDOMNode.react/no-danger — warn against dangerouslySetInnerHTML
react/no-danger — warn against dangerouslySetInnerHTML
dangerouslySetInnerHTML creates XSS risk. The rule warns rather than errors to allow intentional usage, but every use should be carefully reviewed.react/no-danger-with-children — disallow children alongside dangerouslySetInnerHTML
react/no-danger-with-children — disallow children alongside dangerouslySetInnerHTML
dangerouslySetInnerHTML — React will throw at runtime.react/no-array-index-key — disallow array index as key prop
react/no-array-index-key — disallow array index as key prop
react/no-unstable-nested-components — disallow component definitions inside render
react/no-unstable-nested-components — disallow component definitions inside render
react/no-access-state-in-setstate — disallow this.state inside setState
react/no-access-state-in-setstate — disallow this.state inside setState
this.state inside setState is unreliable because state updates are batched. Use the functional form of setState instead.react/no-string-refs — disallow string refs
react/no-string-refs — disallow string refs
ref="myRef") are a legacy API. Use React.createRef() or the useRef hook instead.react/jsx-no-target-blank — require rel on target=_blank links
react/jsx-no-target-blank — require rel on target=_blank links
target="_blank" must include rel="noopener noreferrer" to prevent tab-napping attacks. This applies to dynamic links too.react/jsx-no-script-url — disallow javascript: URLs in JSX props
react/jsx-no-script-url — disallow javascript: URLs in JSX props
href="javascript:void(0)" execute code and are an XSS vector. Also applied to the to prop of Link components.react/no-unescaped-entities — disallow unescaped HTML entities
react/no-unescaped-entities — disallow unescaped HTML entities
", ', {, and > must be escaped in JSX text content to avoid parser ambiguity.react/jsx-no-constructed-context-values — disallow non-stable context values
react/jsx-no-constructed-context-values — disallow non-stable context values
react/no-unused-state — disallow unused state
react/no-unused-state — disallow unused state
react/no-redundant-should-component-update — disallow shouldComponentUpdate in PureComponent
react/no-redundant-should-component-update — disallow shouldComponentUpdate in PureComponent
React.PureComponent already performs shallow prop and state comparison. Adding shouldComponentUpdate overrides this behavior and is redundant (or a misuse of PureComponent).JSX file conventions
react/jsx-filename-extension — JSX only in .jsx files
react/jsx-filename-extension — JSX only in .jsx files
.jsx files. This makes it easy to identify React components by file extension.react/jsx-pascal-case — require PascalCase for component names
react/jsx-pascal-case — require PascalCase for component names
SVG) are allowed.react/self-closing-comp — require self-closing tags for childless elements
react/self-closing-comp — require self-closing tags for childless elements
react/jsx-fragments — prefer shorthand fragment syntax
react/jsx-fragments — prefer shorthand fragment syntax
syntax)react/jsx-no-useless-fragment — disallow unnecessary fragments
react/jsx-no-useless-fragment — disallow unnecessary fragments