question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`no-confusing-arrow` flags conditionals inside parentheses.

See original GitHub issue

ESLint 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:closed
  • Created 8 years ago
  • Reactions:5
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
shinzuicommented, May 8, 2016

Is allowParens set to true supposed to work with no-extra-parens. It’s now triggering “Gratuitous parentheses around expression. (no-extra-parens)”.

2reactions
dtinthcommented, Feb 22, 2016

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: => (.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found