no-typos
Configuration
Disallow common typos in React component declarations.
Rule Details
This rule catches casing mistakes in React-specific identifiers that are easy to miss because the surrounding code still runs — just not the way the author expected.
It flags four classes of typo:
- Static class property names on React components:
propTypes,contextTypes,childContextTypes,defaultProps. Any identifier whose lowercased form equals one of these but whose casing differs is reported — whether declared as a static class field (static PropTypes = {}) or assigned externally (Component.PropTypes = {}). - React lifecycle method names on class components or inside
createReactClass({ ... }):- Instance:
getDefaultProps,getInitialState,getChildContext,componentWillMount,UNSAFE_componentWillMount,componentDidMount,componentWillReceiveProps,UNSAFE_componentWillReceiveProps,shouldComponentUpdate,componentWillUpdate,UNSAFE_componentWillUpdate,getSnapshotBeforeUpdate,componentDidUpdate,componentDidCatch,componentWillUnmount,render. - Static:
getDerivedStateFromProps.
- Instance:
- Static lifecycle declared non-static:
getDerivedStateFromProps(or a casing variant of it) declared as an instance method triggersstaticLifecycleMethodin addition to any casing typo. PropTypesusage errors — when aprop-typesorreactimport is present:- A property name in
PropTypes.<name>/<alias>.<name>that is not one of the keys exported byprop-types(e.g.PropTypes.Number,PropTypes.bools) emitstypoPropType. - A chain qualifier that is not
isRequired(e.g..isrequired) emitstypoPropTypeChain. import 'react'with no binding emitsnoReactBinding.import 'prop-types'with no binding emitsnoPropTypesBinding.
- A property name in
Component detection
A class is considered a React component when it extends Component or
PureComponent — either as a bare identifier or qualified by the React
pragma (React.Component by default, configurable via
settings.react.pragma). Classes with a JSDoc @extends React.Component /
@augments React.Component tag are also recognized.
For Component.PropTypes = ... / Component.propTypes = ... assignments the
rule resolves Component file-wide to:
- a class (declared with either
class Fooorconst Foo = class) matching the above extends rule, or - a function declaration / expression / arrow function whose body directly
contains a
return <jsx />.
Classes and functions that don't satisfy those conditions — including
React.forwardRef / React.memo / styled.xxx results — are not treated as
components, matching eslint-plugin-react's behavior.
Differences from ESLint
- Computed / bracket-notation access is not tracked. Upstream documents
Component['PropTypes']as "currently not supported" and this rule follows suit — onlyPropertyAccessExpression(a.b) is examined. Code likeFoo['prop' + 'Types'] = {}silently passes, matching ESLint.
Examples of incorrect code for this rule:
Examples of correct code for this rule: