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.

Rule proposal: indentation of closing bracket

See original GitHub issue

Similar to #14 and #15, it might be nice to have a rule that specifies the indentation of closing brackets for JSX.

For non-self-closing tags, I’ve seen three different patterns: on the same line as last prop (should maybe be handled by #14), on new line but same indentation as props, and on new line but same indentation as opening bracket.

Same line:

<MyComponent
  myProp="...">
  Children
</MyComponent>

New line, same indentation as props:

<MyComponent
  myProp="..."
  >
  Children
</MyComponent>

New line, same indentation as opening bracket:

<MyComponent
  myProp="..."
>
  Children
</MyComponent>

For self-closing tags, I’ve seen the same patterns, but one might want to be able to specify differences. For example, one might want to have non-self-closing be at same indentation as props, but self closing to be at same indentation as opening bracket:

<MyComponent
  myProp="..."
  >
  Children
</MyComponent>

<MyComponent
  myProp="..."
/>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yannickcrcommented, Nov 18, 2015

Since v3.4.0 you can enforce different style for non-empty and self-closing tags.

You should be able to enforce this style with the following configuration:

"jsx-closing-bracket-location": [1, {
  "nonEmpty": "props-aligned", // Align the bracket with the last prop
  "selfClosing": "tag-aligned" // Align the bracket with the opening tag
}]
0reactions
lencionicommented, Nov 18, 2015

Ah! I see. Thanks. I think I misread the documentation. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Closing bracket does not match indentation of ... - Flake8 Rules
Closing brackets should match the same indentation level of the line that their opening bracket started on.
Read more >
PEP 8: Hanging Indentation and Closing Brackets in Python
This article shows how to line up the closing braces, brackets, and parentheses correctly in Python. This is called “hanging indentation” and it's...
Read more >
Optional Braces - Scala 3 - EPFL
Scala 3 enforces some rules on indentation and allows some occurrences of braces {. ... This rule is helpful for finding missing closing...
Read more >
ESlint enforce closing brackets for functions etc on same ...
The indent rule covers what you're looking for, though it make be overkill if this one case is all you want to check....
Read more >
Tags · Styleguide JavaScript
Closing Bracket Indentation. If a component has multi-line properties, close its tag on a new line. ESLint: react/jsx-closing-bracket-location ...
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