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-confusing-arrow
flags conditionals inside parentheses.
#5332
Comments
Confirmed. Do you want to submit a pull request for this? |
What about this?
|
This bug is even worse with |
Hey! I just ran into this problem.. input.replace(tags, ($0, $1) => (allowed.indexOf(`<${$1.toLowerCase()}>`) > -1 ? $0 : '')); triggers input.replace(tags, ($0, $1) => { return allowed.indexOf(`<${$1.toLowerCase()}>`) > -1 ? $0 : ''; }); triggers I think that allowng parentheses around the expression will be great. |
Would love to work on it, but have been quite busy, so I am not sure whether I’ll have time to do it. @nzakas @jeremejevs @gilbarbara What do you think about @alberto’s case? Does For me, I think it’s pretty clear that it’s a function that returns some value, because I get used to seeing this: |
I think an arrow shouldn't be considered "confusing" (as in, could be confused with |
@alberto Your example isn't limited to ternary, though. Any (every?) "concise body" arrow function can be confusing in one way or another, no? var a = 2;
var x = a >= (true ? 2 : 3);
var y = a >= (b || a);
var z = a >= Math.sin(a); Isn't this static typing jurisdiction? |
@jeremejevs Every arrow function with a concise body and taking exactly one argument, yes. I think that's (or should be) the purpose of the rule. |
This update _temporarily_ removes `no-confusing-arrow`, so our override can be removed. More info about this eslint/eslint#5332
Working on this, pretty close. Added a |
Is |
ESLint Version: 2.1.0
This is a pattern I use frequently in JavaScript code:
Note that the conditionals are inside parentheses. In this case, the meaning is not ambiguous. You can’t interpret
a => (1 ? 2 : 3)
as(a >= 1) ? 2 : 3
.Test Case
Expected Result
No lint errors.
Actual Result
Arrow function used ambiguously with a conditional expression. (no-confusing-arrow)
The text was updated successfully, but these errors were encountered: