JS.REACT.JSX.SPACE.BEFORE.CLOSING

Validate spacing before closing bracket in JSX

Deprecation notice: This rule is deprecated. Please use the "beforeSelfClosing" option of the jsx-tag-spacing (https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md) rule instead.

Enforce or forbid spaces before the closing bracket of self-closing JSX elements.

Fixable: This rule is automatically fixable using the --fix flag on the command line.

Rule Details

This rule checks if there is one or more spaces before the closing bracket of self-closing JSX elements.

This rule takes one argument. If it is "always" then it warns whenever a space is missing before the closing bracket. If "never" then it warns if a space is present before the closing bracket. The default value of this option is "always".

Examples of incorrect code for this rule, when configured with "always":

Copy
<Hello/>
<Hello firstname="John"/>

Examples of correct code for this rule, when configured with "always":

Copy
<Hello />
<Hello firstName="John" />
<Hello
  firstName="John"
  lastName="Smith"
/>

Examples of incorrect code for this rule, when configured with "never":

Copy
<Hello />
<Hello firstName="John" />

Examples of correct code for this rule, when configured with "never":

Copy
<Hello/>
<Hello firstname="John"/>
<Hello
  firstName="John"
  lastName="Smith"
/>

When Not To Use It

You can turn this rule off if you are not concerned with the consistency of spacing before closing brackets.

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/