Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin-jsx): add jsx-self-closing-comp #22

Merged
merged 3 commits into from
Oct 19, 2023

Conversation

zhiyuanzmj
Copy link
Contributor

Disallow extra closing tags for components without children (react/self-closing-comp)

🔧 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 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"></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>;

var HelloSpace = <Hello>{' '}</Hello>;

Reference

https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md

@netlify
Copy link

netlify bot commented Oct 16, 2023

Deploy Preview for eslint-stylistic ready!

Name Link
🔨 Latest commit cfc9de6
🔍 Latest deploy log https://app.netlify.com/sites/eslint-stylistic/deploys/652cdf2c1f50990008d58693
😎 Deploy Preview https://deploy-preview-22--eslint-stylistic.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@antfu
Copy link
Member

antfu commented Oct 16, 2023

Looks good. I think we'd better to rename the rule to jsx-self-closing-comp to have a clear scope.

@zhiyuanzmj zhiyuanzmj changed the title feat(eslint-plugin-jsx): add self-closing-comp feat(eslint-plugin-jsx): add jsx-self-closing-comp Oct 18, 2023
@antfu antfu merged commit 93c5b52 into eslint-stylistic:main Oct 19, 2023
11 checks passed
@zhiyuanzmj zhiyuanzmj deleted the feat/self-closing-comp branch October 20, 2023 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants