Skip to content

react/self-closing-comp Style ​

🚧 An auto-fix is still under development.

What it does ​

Detects components without children which can be self-closed to avoid unnecessary extra closing tags.

A self closing component which contains whitespace is allowed except when it also contains a newline.

Examples ​

Examples of incorrect code for this rule:

jsx
const elem = <Component linter="oxlint"></Component>;
const dom_elem = <div id="oxlint"></div>;
const welem = <div id="oxlint"></div>;

Examples of correct code for this rule:

jsx
const elem = <Component linter="oxlint" />;
const welem = <Component linter="oxlint"> </Component>;
const dom_elem = <div id="oxlint" />;

References ​

Released under the MIT License.