-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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-indent-props false positive in ternary operator #2841
Comments
This looks like a correct error to me, the code should be: const Component = (props) => {
return props.prop
? <input
type="email"
/>
: "";
}; |
@ljharb Thanks for the tip. But I wonder why the indentation convention you are using is the correct one. Is this convention enforced by the jsx-indent-props rule? I'm asking because if I adapt my styling the way you suggest, then this is against eslint's own indent rule and eslint remarks that the indentation is now too high: If this is not a bug but a fix, then it seems to me that two contradicting styling conventions for multi-line expressions inside a ternary operator are tried to be enforced, and I wonder how I can adjust the settings of both rules to follow one consistent approach. |
hmm, interesting. Personally, I surround all multiline jsx in parens, like this: const Component = (props) => {
return props.prop
? (
<input
type="email"
/>
): "";
}; which i believe would pass |
Yes, this works for me and passes both rules. Thank you. I don't prefer any convention over the other so basically I'm happy to adapt my codebase. But in the end I think it is a matter of taste. The rule configs did coexist before 7.21.4. The change resulting in the error I'm getting was proposed in #647 and introduced with #2808 My suggestion is to allow the user the decision if the indent level should be increased by a preceding I'm not a versed eslint developer but I could try to create a PR if you like. |
I think a PR that adds an additional option that controls, in a multiline ternary, whether the |
I've created a PR: #2846 |
Facing same issue. |
Since 7.21.4 I get a
react/jsx-indent-props
false positive when using props in a ternary operator. I thought issue I'm having is the same as #2828 and thus would be fixed in 7.21.5, but it looks like #2828 is fixed in 7.21.5 and this is not. 7.21.3 works fine. See below for eslint config.Error
Code
eslint-Config
The text was updated successfully, but these errors were encountered: