react/self-closing-comp
eslint-plugin-react
Safe autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/self-closing-comp": "error",
},
},
];var contentContainer = <div className="content"></div>;
var HelloJohn = <Hello name="John"></Hello>;
var HelloJohnCompound = <Hello.Compound name="John"></Hello.Compound>;var contentContainer = <div className="content" />;
var intentionalSpace = <div>{' '}</div>;
var HelloJohn = <Hello name="John" />;
var HelloJohnCompound = <Hello.Compound name="John" />;
var Profile = <Hello name="John"><img src="picture.png" /></Hello>;
var ProfileCompound = <Hello.Compound name="John"><img src="picture.png" /></Hello.Compound>;
var HelloSpace = <Hello>{' '}</Hello>;Examples from the ESLint documentation.
react/self-closing-comp
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/self-closing-comp": "error",
},
},
];react/self-closing-comp
react plugin · style
{
"plugins": [
"react"
],
"rules": {
"react/self-closing-comp": "error"
}
}style/useSelfClosingElements
style · since 1.0.0
{
"linter": {
"rules": {
"style": {
"useSelfClosingElements": "error"
}
}
}
}Disallow using another component's propTypes
Enforce PascalCase for user-defined JSX components
Enforce shorthand or standard form for React fragments
Disallow .bind() or arrow functions in JSX props