Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upPrevent missing parentheses around multiline JSX (jsx-wrap-multilines) #710
Comments
feross
added
the
enhancement
label
Dec 5, 2016
This comment has been minimized.
This comment has been minimized.
|
Isn't this already a thing? Any way, I usually do: var Hello = React.createClass({
render: function() {
return (<div>
<p>Hello {this.props.name}</p>
</div>)
}
}) |
This comment has been minimized.
This comment has been minimized.
|
This matches how I use React as well. It also works for this style, which I've seen being used around: export const Hello = ({ name} ) => (
<div>
<p>Hello {name}</p>
</div>
) |
This comment has been minimized.
This comment has been minimized.
pluma
commented
Jan 24, 2017
|
AFAICT the proposed rule seems to be a de facto standard in the React community. I'm so used to it that I often even wrap single-line JSX in parens (and indent it as multi-line) but that seems excessive. |
feross
added this to the
standard v11 milestone
Apr 4, 2017
This comment has been minimized.
This comment has been minimized.
plonko
commented
Nov 2, 2017
|
Anyone know of anything like this for ES Lint? This is my main pet peeve in JSX! :) |
feross
modified the milestones:
standard v12,
standard v13
Aug 28, 2018
This comment has been minimized.
This comment has been minimized.
justnewbee
commented
Dec 26, 2018
•
|
i really don't like it... my favorite style is without those parentheses, i think the jsx structure is quite clear by itself, no need to wrap them i want to "never" it and report error on those wrapped, but there seem not to have an option to do so... please add one, for example |
This comment has been minimized.
This comment has been minimized.
jsphstls
commented
Jun 18, 2019
|
The necessity of parenthesis depends on whether misaligned JSX tags are allowed: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md The added cognitive complexity of optional wrapping parenthesis is not always needed because JSX must be wrapped in a single parent anyways. The wrapping parenthesis are only useful after const something =
<div>
<button />
</div>
const something = () =>
<div>
<button />
</div>
const something = () => {
console.log('something')
return (
<div>
<button />
</div>
)
}
const something = isWhatever
? (
<div>
<button />
</div>
) : (
<span>
<button />
</span>
) |
feross
modified the milestones:
standard v13,
standard v14
Jul 5, 2019
This comment has been minimized.
This comment has been minimized.
|
The configuration that I want to go with is:
I think this configuration is the least controversial, best for readability (in my subjective opinion), and seems to match the React community's dominant style. This currently passes the entire test suite. (We don't actually have that many repos with JSX in the suite, though we do have bitmidi.com, webtorrent-desktop, and a few others.) Here's a list of what is allowed and not allowed
|
feross
closed this
in
ccaf439
Aug 14, 2019
This comment has been minimized.
This comment has been minimized.
|
Let's ship it in |
feross commentedDec 5, 2016
Wrapping multiline JSX in parentheses can improve readability.
Rule page: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md (Automatically fixable.)
This is an error:
This is not an error: