Rule Change: no-constant-binary-expression should report `<expr1> ?? <non-nullish> ?? <expr2>`
See original GitHub issueRule 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:
- Created a year ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
No results found
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 Free
Top 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
Updated the title and marked accepted. @amareshsm this is now ready to implement.
In case we are updating the
no-constant-binary-expression
rule to report an unnecessary nullish coalescing operator then I will work this.