-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Prevent missing parentheses around multiline JSX (jsx-wrap-multilines) #710
Comments
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 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>
) |
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. |
Anyone know of anything like this for ES Lint? This is my main pet peeve in JSX! :) |
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 |
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>
) |
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
|
Let's ship it in |
Isn't it true though that parens are not needed in ternaries? You can maintain proper alignment without any parens at all:
|
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:
The text was updated successfully, but these errors were encountered: