Useless PropTypes declaration should be removed

  • REACT_USELESS_PROP_TYPES
  • Code Quality
  • Low
  • react

This rule applies when a PropTypes declaration exists for a property but the property is not used for the implementation of the component.

For maintainability, it is recommended to remove useless PropTypes declarations.

Noncompliant Code Example

View with compliant examples side by side
import React from 'react';
import PropTypes from 'prop-types';

class Hello extends React.Component {
    render() {
        return <div>Hello, {this.props.name}</div>;
    }
}

Hello.propTypes = {
    name: PropTypes.string,
    age: PropTypes.number // REACT_USELESS_PROP_TYPES alarm because this property 'age' is not used.
};

Compliant Code Example

View with noncompliant examples side by side
import React from 'react';
import PropTypes from 'prop-types';

class Hello extends React.Component {
    render() {
        return <div>Hello, {this.props.name}</div>;
    }
}

Hello.propTypes = {
    name: PropTypes.string
};

Version

This rule was introduced in DeepScan 1.3.0-beta.

See