react/prop-types
eslint-plugin-react
No autofixRecommended
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/prop-types": "error",
},
},
];function Hello({ name }) {
return <div>Hello {name}</div>;
// 'name' is missing in props validation
}
var Hello = createReactClass({
propTypes: {
firstname: PropTypes.string.isRequired
},
render: function() {
return <div>Hello {this.props.firstname} {this.props.lastname}</div>;
// 'lastname' type is missing in props validation
}
});
// Or in ES6
class Hello extends React.Component {
render() {
return <div>Hello {this.props.firstname} {this.props.lastname}</div>;
// 'lastname' type is missing in props validation
}
}
Hello.propTypes = {
firstname: PropTypes.string.isRequired
}interface Props {
age: number
}
function Hello({ name }: Props) {
return <div>Hello {name}</div>;
// 'name' type is missing in props validation
}// destructured default prop values
function Foo({ bar = "" }): JSX.Element {
return <div>{bar}</div>;
}
function Foo({ bar = "" as string }): JSX.Element {
return <div>{bar}</div>;
}type Props = {
name: string
}
class Hello extends React.Component<Props> {
render() {
return <div>Hello {this.props.name}</div>;
}
}function Hello() {
return <div>Hello World</div>;
}
// Referencing an external object disable the rule for the component
function Hello({ name }) {
return <div>Hello {name}</div>;
}
Hello.propTypes = myPropTypes;Examples from the ESLint documentation.
react/prop-types
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/prop-types": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Disallow usage of unknown DOM property
Disallow target="_blank" attribute without rel="noreferrer"
Disallow missing displayName in a React component definition
Disallow unescaped HTML entities from appearing in markup