`no-confusing-arrow` flags conditionals inside parentheses.
See original GitHub issueESLint Version: 2.1.0
This is a pattern I use frequently in JavaScript code:
const renderItem = item => (isSeparator(item)
? React.createElement(Separator)
: React.createElement(MenuItem, item)
)
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
/* eslint no-confusing-arrow: 2 */
var x = a => (1 ? 2 : 3)
Expected Result
No lint errors.
Actual Result
Arrow function used ambiguously with a conditional expression. (no-confusing-arrow)
Issue Analytics
- State:
- Created 8 years ago
- Reactions:5
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Rules - ESLint - Pluggable JavaScript Linter
Rules in ESLint are grouped by type to help you understand their purpose. ... Disallow assignment operators in conditional expressions. Categories:.
Read more >Parentheses in Python Conditionals - Stack Overflow
I have a simple question regarding the use of parentheses in Python's conditional statements. The following two snippets work just ...
Read more >Enforce the use of u flag on RegExp (require-unicode-regexp)
This rule aims to enforce the use of u flag on regular expressions. Examples of incorrect code for this rule: /*eslint require-unicode-regexp: error ......
Read more >ESLint equivalents in Elm - Elmcraft
disallow assignment operators in conditional expressions. Elm doesn't support mutating values. no-const-assign. (recommended).
Read more >tslint-eslint-rules - npm
Start using tslint-eslint-rules in your project by running `npm i ... no-conditional-assignment, disallow assignment in conditional ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is
allowParens
set totrue
supposed to work withno-extra-parens
. It’s now triggering “Gratuitous parentheses around expression. (no-extra-parens)”.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
var x = a => (true ? 2 : 3)
look confusing?For me, I think it’s pretty clear that it’s a function that returns some value, because I get used to seeing this:
=> (
.