question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Require JSX closing tag to be aligned with the opening tag (react/jsx-closing-tag-location)

See original GitHub issue

This rule checks all JSX multiline elements with children (non-self-closing) and verifies the location of the closing tag. The expectation is that the closing tag is aligned with the opening tag on its own line.

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md

The following patterns are considered warnings:

<Hello>
  marklar
  </Hello>
<Hello>
  marklar</Hello>

The following are not considered warnings:

<Hello>
  marklar
</Hello>
<Hello>marklar</Hello>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ferosscommented, Sep 11, 2019

@joke2k The intended style is to add parens anytime you have a multiline JSX statement.

  render () {
    return (
      <div>
        Closing tag below where should be?
      </div>
    )
  }

I’m not sure why the autofixer isn’t doing that for you. Looks like we need to play with the JSX rules some more to get what we want.

3reactions
joke2kcommented, Sep 11, 2019

@feross I think that @MatanBobi means using non-self-closing tag with return:

  render () {
    return <div>
      Closing tag below where should be?
    </div>
  }

With this rule, this style raises an error (not aligned to open tag) and if I try to --fix it:

  render () {
    return <div>
      Closing tag below where should be?
           </div>
  }

which raises react/jsx-indent-problem and is ugly.

The only way to fix it is putting all in one line:

  render () {
    return <div>Closing tag below where should be?</div>
  }

but is not really sustainable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "react/jsx-closing-bracket-location" in WebStorm
Just created a new line with the /> aligned with the original tag. Share.
Read more >
Expected corresponding JSX closing tag error in React
The React.js error "Expected corresponding JSX closing tag" occurs when we forget to close a tag in our JSX code. To solve the...
Read more >
Allow reformat to place closing tag in new line in JSX - YouTrack
Trying to follow https://github.com/airbnb/javascript/tree/master/react#alignment with closing tag on it's own line if multi line.
Read more >
Tags · Styleguide JavaScript
If a component has multi-line properties, close its tag on a new line. ESLint: react/jsx-closing-bracket-location. Examples. ⇣ Incorrect code for this rule: < ......
Read more >
Rule request: JSX indentation and tag positioning #337
9:1 The closing bracket must be aligned with the opening tag (expected column 15) react/jsx-closing-bracket-location ✖ 10:1 Expected closing tag to match ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found