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

react/jsx-closing-bracket-location not working #31

Open
Richienb opened this issue Oct 22, 2021 · 7 comments
Open

react/jsx-closing-bracket-location not working #31

Richienb opened this issue Oct 22, 2021 · 7 comments

Comments

@Richienb
Copy link
Contributor

Currently, the rule requires tags to be aligned:

'react/jsx-closing-bracket-location': [
'error',
{
nonEmpty: 'tag-aligned',
selfClosing: false
}
],

In this situation, no amount of tabs would achieve that (line 6):

{via ? <div style={{
	display: 'flex',
	flexDirection: 'column',
	textAlign: 'center',
}}
       >
	<div>{destination}</div>
	<div>via {via}</div>
</div> : <span>{longName}</span>}

7 spaces worth of space are needed which can't be represented in tabs.

@Richienb
Copy link
Contributor Author

This appears to fix the problem:

'react/jsx-closing-bracket-location': [
	'error',
	{ 
-		nonEmpty: 'tag-aligned',
+       nonEmpty: 'line-aligned',
		selfClosing: false
	}
],

@sindresorhus
Copy link
Member

That allows for code like this though:

var x = function() {
  return <Say
    firstName="John"
    lastName="Smith"
         >
    Hello
         </Say>;
};

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

@sindresorhus
Copy link
Member

Are you sure this is just not a bug/limitation in the rule?

@Richienb
Copy link
Contributor Author

Are you sure this is just not a bug/limitation in the rule?

Yes, there is a limitation in the rule which means tag-aligned can't always give good alignment without having to use spaces.

@sindresorhus
Copy link
Member

sindresorhus commented Jan 3, 2022

can't always give good alignment

But neither can line-aligned.

@sindresorhus
Copy link
Member

I think you should open an issue eslint-plugin-react.

@ljharb
Copy link

ljharb commented Jan 27, 2022

To clarify: the rule was originally written with the airbnb config in mind, which requires parens around multiline jsx, so you'd always write it like this, whether you're using spaces or tabs:

var x = function() {
  return (
    <Say
      firstName="John"
      lastName="Smith"
    >
      Hello
    </Say>
  );
};

There's likely to be edge cases for scenarios that weren't holistically considered. (Further discussion about closing-bracket-location can happen on the linked issue)

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

No branches or pull requests

3 participants