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 Change: no-constant-binary-expression should report `<expr1> ?? <non-nullish> ?? <expr2>`

See original GitHub issue

Rule details

Inform developer of potentially unnecessary nullish coalescing operator

Related ECMAScript feature

Nullish coalesing operator

What type of rule is this?

Suggests an alternate way of doing something

Example code

// fail
window.abc ?? "any non-nullish value" ?? "any non-nullish value" // warn (the last nullish coalesing operator will never be used)
window.abc ?? undefined ?? "any non-nullish value" // warn (the first nullish coalescing operator is skipped)
window.abc ?? null ?? "any non-nullish value" // warn (the first nullish coalescing operator is skipped)

Why should this rule be in the core instead of a plugin?

I don’t know.

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Dec 14, 2022

Updated the title and marked accepted. @amareshsm this is now ready to implement.

1reaction
amareshsmcommented, Dec 12, 2022

In case we are updating the no-constant-binary-expression rule to report an unnecessary nullish coalescing operator then I will work this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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