eslint-config-xo-react icon indicating copy to clipboard operation
eslint-config-xo-react copied to clipboard

`react/jsx-closing-bracket-location` not working

Open Richienb opened this issue 2 years ago • 7 comments

Currently, the rule requires tags to be aligned:

https://github.com/xojs/eslint-config-xo-react/blob/e29b624ba20b00f7ada7889fcc7d936f8035b94e/index.js#L86-L92

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 avatar Oct 22 '21 06:10 Richienb

This appears to fix the problem:

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

Richienb avatar Oct 22 '21 06:10 Richienb

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 avatar Oct 24 '21 03:10 sindresorhus

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

sindresorhus avatar Oct 24 '21 03:10 sindresorhus

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.

Richienb avatar Oct 24 '21 06:10 Richienb

can't always give good alignment

But neither can line-aligned.

sindresorhus avatar Jan 03 '22 00:01 sindresorhus

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

sindresorhus avatar Jan 03 '22 00:01 sindresorhus

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)

ljharb avatar Jan 27 '22 21:01 ljharb