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.

Rule `no-extra-parens` shouldn't error on logical operators wrapped in parens in a ternary condition

See original GitHub issue
~/dev
❯ eslint --version
v2.9.0

~/dev
❯ echo "(foo || bar) ? 'error' : 'warning'" | eslint --stdin --rule='no-extra-parens:2'

<text>
  1:1  error  Gratuitous parentheses around expression  no-extra-parens

✖ 1 problem (1 error, 0 warnings)

The ternary (foo || bar) ? 'error' : 'warning' without the parens is ambiguous for people not knowing the precedence rules, which applies to a lot of devs. I would have expected the rule not to fail on this.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, Jan 10, 2017

@bdougherty Would you like to make a new issue with your proposal? You’d have a lot more visibility than you do here!

1reaction
kaicataldocommented, Aug 26, 2016

@eslint/eslint-team Other thoughts on this? This hasn’t seen much activity, but also didn’t get much discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-extra-parens - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Add option to the `no-nested-ternary` rule that allows parens ...
Looking at the no-extra-parens documentation, I see that the "all" option has exceptions baked into it, for IIFEs and the wrap-regex rule.
Read more >
Rules - JavaScript Standard Style
Wrap conditional assignments with additional parentheses. This makes it clear that the expression is intentionally an assignment ( = ) rather than a...
Read more >
C static code analysis: The ternary operator should not be used
Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in ... Switch statement conditions should not have essentially boolean type.
Read more >
Conditional branching: if, '?' - The Modern JavaScript Tutorial
statement evaluates the expression in its parentheses and converts the result to a boolean. Let's recall the conversion rules from the chapter ...
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