GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — eslint-plugin-react/docs/rules/self-closing-comp.md at master · jsx-eslint/eslint-plugin-react

Expand file tree

/

self-closing-comp.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
98 lines (59 loc) · 2.3 KB
/

self-closing-comp.md

Copy path

File metadata and controls

98 lines (59 loc) · 2.3 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

react/self-closing-comp

📝 Disallow extra closing tags for components without children.

🔧 This rule is automatically fixable by the --fix CLI option.

Components without children can be self-closed to avoid unnecessary extra closing tag.

Rule Details

Examples of incorrect code for this rule:

var contentContainer = <div className="content"></div>;

var HelloJohn = <Hello name="John"></Hello>;

var HelloJohnCompound = <Hello.Compound name="John"></Hello.Compound>;

Examples of correct code for this rule:

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>;

Rule Options

The rule can take one argument to select types of tags, which should be self-closed when this is possible. By default custom components tags and html tags should be self-closed.

...
"react/self-closing-comp": ["error", {
  "component": true,
  "html": true
}]
...

component

When true, custom components tags should be self-closed.

Examples of incorrect code for this rule:

var HelloJohn = <Hello name="John"></Hello>;

Examples of correct code for this rule:

var contentContainer = <div className="content"></div>;

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>;

html

When true, html components tags should be self-closed.

Examples of incorrect code for this rule:

var contentContainer = <div className="content"></div>;

Examples of correct code for this rule:

var contentContainer = <div className="content" />;

var contentContainer = <div className="content"><div /></div>;

var intentionalSpace = <div>{' '}</div>;
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.