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.

Warn about mixing logical and ternary operators

See original GitHub issue

What rule do you want to change? no-mixed-operators

Does this change cause the rule to produce more or fewer warnings? more

How will the change be implemented? (New option, new default behavior, etc.)? new option with default behaviour to warn

Please provide some example code that this change will affect:

// what is priority of this? rule should warn of using brackets explicitly
obj.someValue || conditionSatisfied ? 'good' : 'bad'

// 1 option - rule should not warn
(obj.someValue || conditionSatisfied) ? 'good' : 'bad'

// 2 option - rule should not warn
obj.someValue || (conditionSatisfied ? 'good' : 'bad')

What does the rule currently do for this code? it does not warn user about mixed logical and ternary expressions

What will the rule do after it’s changed? warn to use brackets around to make it explicit what the priority is

Are you willing to submit a pull request to implement this change? nope, with this issue, I am just checking if this would make sense Might be related to https://github.com/eslint/eslint/issues/7903

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
karthikkpcommented, Jul 17, 2019

@mysticatea @platinumazure The changes have been made for this and a PR is open for review.

0reactions
platinumazurecommented, May 18, 2019

Thanks @mysticatea. In that case, I’m 👍 for this enhancement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I use a ternary operator mixed with logical OR?
So I said to myself instead of using boolean type for trigger variable, let me use int type for the same variable. Such...
Read more >
no-mixed-operators - ESLint - Pluggable JavaScript Linter
This rule warns when different operators are used consecutively without parentheses in an expression.
Read more >
Nullish coalescing operator (??) - JavaScript - MDN Web Docs
The nullish coalescing (??) operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null ...
Read more >
Conditional Operator - an overview | ScienceDirect Topics
is also called a ternary operator because it takes three inputs. ... The tests can be compounded by using logical operators, as follows:....
Read more >
Nullish coalescing operator '??' - The Modern JavaScript Tutorial
This is a recent addition to the language. Old browsers may need polyfills. The nullish coalescing operator is written as two question marks...
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