Skip to content

Latest commit

 

History

History
57 lines (44 loc) · 1.55 KB

forbid-prop-types.md

File metadata and controls

57 lines (44 loc) · 1.55 KB

Forbid certain propTypes (forbid-prop-types)

By default this rule prevents vague prop types with more specific alternatives available (any, array, object), but any prop type can be disabled if desired. The defaults are chosen because they have obvious replacements. any should be replaced with, well, anything. array and object can be replaced with arrayOf and shape, respectively.

Rule Details

This rule checks all JSX components and verifies that no forbidden propsTypes are used. This rule is off by default.

The following patterns are considered warnings:

var Component = React.createClass({
  propTypes: {
    a: React.PropTypes.any,
    r: React.PropTypes.array,
    o: React.PropTypes.object
  },
...
});

class Component extends React.Component {
  ...
}
Component.propTypes = {
  a: React.PropTypes.any,
  r: React.PropTypes.array,
  o: React.PropTypes.object
};

class Component extends React.Component {
  static propTypes = {
    a: React.PropTypes.any,
    r: React.PropTypes.array,
    o: React.PropTypes.object
  }
  render() {
    return <div />;
  }
}

Rule Options

...
"react/forbid-prop-types": [<enabled>, { "forbid": [<string>] }]
...

forbid

An array of strings, with the names of React.PropTypes keys that are forbidden. The default value for this option is ['any', 'array', 'object'].

When not to use

This rule is a formatting/documenting preference and not following it won't negatively affect the quality of your code. This rule encourages prop types that more specifically document their usage.