Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Documentation Request Please Confirm You Have Done The Following...
- I have looked for existingopen or closed documentation requests that match my proposal.
- I haveread the FAQ and my problem is not listed.
Suggested Changes
I'm reading through the documentation inhttps://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare/#fixer and seeing the following part:
Comparison | Fixer Output |
---|---|
nullableBooleanVar === false | nullableBooleanVar ?? true |
nullableBooleanVar !== false | !(nullableBooleanVar ?? true) |
I believe both of them are wrong, i.e. the statement incomparison
andfixer output
are not equal.
To show how those are wrong, we can simply compare final evaluation result for each possible value ofnullableBooleanVar
=true
,false
, andundefined
. (null
will be treated as same asundefined
).
VariablenullableBooleanVar | ComparisonnullableBooleanVar === false | Fixer OutputnullableBooleanVar ?? true |
---|---|---|
true | false | true |
false | true | false |
undefined | false | true |
As shown above, we can see that the reportedFixer Output
on the right-side will use expression that evaluate to different value from the original code on the middle.
VariablenullableBooleanVar | ComparisonnullableBooleanVar !== false | Fixer Output!(nullableBooleanVar ?? true) |
---|---|---|
true | true | false |
false | false | true |
undefined | true | false |
Again, as shown above, we can see that the reportedFixer Output
on the right-side will use expression that evaluate to different value from the original code on the middle.
I can't advise about what the correct (expected)Fixer Output
should be. The reason why I read this documentation in the first place is because I'm not sure how to fix my code. Yet the documentation gives incorrect information.
Also, I'm not sure whether this issue is also happen to your Fixer utility, since I'm not using it. I always fix lint error by hand ;-) or IDE.
Thanks.
Affected URL(s)
https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare/#fixer