New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[prefer-nullish-coalescing] Auto-fixer generates incorrect code with optional boolean values #1768
Comments
Yeah, nullish booleans probably shouldn't be handled by the rule. |
same thing happens with (empty) string. and (0) number as well. I gotta say, using the auto-fixer for this rule is currently dangerous. |
|
@bradzacher happy to take a crack this week |
I proposed a change in 1910 and wrote up an explanation (see #1910 (comment)).
I'm duplicating that comment here because I'm hoping to generate discussion to clarify the intention of this rule and whether or not the change proposed in 1910 is safe/correct. The proposed change is to ignore checking a |
It's a difficult thing to get right. When I wrote this rule, I was excited about the new operator finally coming to TS. I wanted to give people a way to help migrate their codebase to it, and gain the benefits of safer separation of nullish and empty cases. The simple short-term fix is to leave rule's logic as-is, but:
The long-term fix is to re-evaluate the intention of the rule, and question whether or not it should even exist in the first place. There's a lot of overlap with this rule and So in the long term I see two paths forward:
My preference is the first option, as it saves people double-configuring things, and seems like a natural extension to |
Sorry everyone, I was very busy for a while then away - I want to get a new PR for this change ASAP - I see that it's apart of the upcoming release. @bradzacher May need some help jumping back into this Did 52b6085 cover this? |
Repro
Expected Result
Running the code above on all combinations of values:
Actual Result
When running the auto-fixer with this rule enabled, the following code gets generated:
Which, using the same values as above in the same order:
So
before(false, true, false);
andafter(false, true, false);
return different values.Versions
@typescript-eslint/eslint-plugin
2.24.0
@typescript-eslint/parser
2.24.0
TypeScript
3.8.3
ESLint
6.8.0
node
12.14.0
npm
6.13.4
The text was updated successfully, but these errors were encountered: