prefer-nullish-coalescing rule
See original GitHub issueHi there,
Please describe what the rule should do: Almost same as typescript-eslint’s prefer-nullish-coalescing.
I think that could be included in the eslint feature. It seems to depend on the type of information of typescript though.
What new ECMAScript feature does this rule relate to?
https://github.com/tc39/proposal-nullish-coalescing
What category of rule is this? (place an “X” next to just one item)
[ ] Warns about a potential error (problem) [X] Suggests an alternate way of doing something (suggestion) [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
a || b; // warn
a ?? b;
if (a || b) {} // warn if ignoreConditionalTests = false
if (a ?? b) {}
(a && b) || c; // warn if ignoreMixedLogicalExpressions = false
(a && b) ?? c;
Why should this rule be included in ESLint (instead of a plugin)? Since Nullish Coalescing operator became a feature of EcmaScript not only typescript.
Are you willing to submit a pull request to implement this rule? Not for now.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (6 by maintainers)
Top GitHub Comments
Thanks for the update!
So the rule would basically disallow
||
in favor of??
? I’m not sure if it makes sense without type information, the rule would be probably unusable due to a lot of false positives.There are probably many places in a codebase where
||
can (and should) be replaced with??
, but sometimes||
has to be||
and I don’t think we can reliably detect that.