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
no-arrow-condition does not recognise legitimate func #4417
Comments
Thanks for the issue! If you're reporting a bug, please be sure to include:
Requesting a new rule? Please see Proposing a New Rule for instructions. |
|
This is expected behavior. Your code is the equivalent of this: var fn = ({height}) => (!isOpened && parseFloat(height).toFixed(1) === '0.0');
// later
{ fn ? null : <div />} You are testing the truthiness of a function, which is always true. |
@nzakas That's wrong, your parser has a precedence bug. Conditional expressions allow logical or expressions as the test, not assignment expressions. |
https://github.com/eslint/eslint/blob/master/lib/rules/no-arrow-condition.js#L73 |
Oh, wow. Yeah there doesn't seem to be any reason for that check. |
@nzakas arrow func in this case is confused with a check in condition. It is not a check, it is a callback function with arguments destructuring. {({height}) => (!isOpened && parseFloat(height).toFixed(1) === '0.0') ?
null :
<div style={{...style, height, overflow: 'hidden'}} {...props}>{children}</div>} which is effectively function render (props) {
var height = props.height;
if (!isOpened && parseFloat(height).toFixed(1) === '0.0') {
return null;
} else {
return <div style={Object.assign({}, style, {height: height, overflow: 'hidden'}) {...props}>{children}</div>;
}
} |
@michaelficarra ah! I see, thanks for explaining. This is a big in Espree then. |
Oops, just saw @mysticatea's comment, so that's an easier fix. |
Interesting. |
When I ported The original plugin would always flag statements like the following because it could be a mistake so the author should instead be explicit and rewrite the arrow function with an explicit return statement. /*eslint-env es6*/
/*eslint no-arrow-condition: 2*/
var fn = a => b ? c : d
// 4:10 - Arrow function used ambiguously with a conditional expression. (no-arrow-condition)
// To fix this write you arrow function like this
var fn = a => { return b ? c : d } There was discussion in the PR about adding an option to allow for conditions in arrow functions and only flag cases where it was a more obvious mistake (like using an arrow function inside an if statement), but I think it was decided to wait for feedback once it went live Should an option on |
We don't like having overlapping rules, so we need to make some kind of change. I'm wondering if we should have something like |
I think that's a good idea. That rule would catch these cases and there'd be no need for an option since that's all the rule would cover. Then |
Cool, let's do that. We will deprecate |
Sounds good, I can work on that. Should I split it up into two PRs (one to create |
Yes, please. |
New: Add no-confusing-arrow rule (ref #4417)
Breaking: deprecate `no-arrow-condition` rule (fixes #4417)
Code from https://github.com/nkbt/react-collapse/blob/master/src/Collapse.js#L45-L53:
The text was updated successfully, but these errors were encountered: