[prefer-nullish-coalescing] Rule is hard too use without major refactors #1313
Labels
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
working as intended
Issues that are closed as they are working as intended
Wasn't sure how to title this and will preface this by saying I understand the semantics of nullish coalescing, and why the
prefer-nullish-coalescing
exists, but in it's current state, it's quite troublesome to enable. My story:--fix
on them all, which worked. Ok cool, this is even more awesome.The crux is that we use empty string/JSX fall-through patterns a lot, for example
providedMessage || "Fallback message"
. The rule however will flag this (rightly so since the value isn't null or undefined, but a string) and convert it toprovidedMessage ?? "Fallback message"
, which is entirely incorrect as it will break our expectation/render.I hope you see the problem here. In it's current state, we have the following options, none of which are ideal/easily solved.
eslint-disable-next-line
comments all over the source for all these string (and number) call sites.The 1st option is probably the best past forward, but is also a lot of work, sometimes too much work. The 2nd option is the worst for obvious reasons. The 3rd option is "acceptable" but we lose so many benefits provided by this rule.
I'm not really looking for a solution here, but hopefully spark some conversation on this, as I'm sure others will run into this.
Possible solutions
||
usage where the left and right sides are both the same type (strings, numbers, etc).The text was updated successfully, but these errors were encountered: