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
fix(eslint-plugin): [prefer-optional-chain] properly disambiguate between boolean
and false
#8685
fix(eslint-plugin): [prefer-optional-chain] properly disambiguate between boolean
and false
#8685
Conversation
Thanks for the PR, @abrahamguo! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8685 +/- ##
=======================================
Coverage 87.23% 87.23%
=======================================
Files 251 251
Lines 12319 12321 +2
Branches 3884 3885 +1
=======================================
+ Hits 10746 10748 +2
Misses 1303 1303
Partials 270 270
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever - I like the changes. Very minimal and clean. Nicely done! 🙌
…ween `boolean` and `false` (typescript-eslint#8685) * make the example from the docs work * revert * allow falsey literals on last operand
…ween `boolean` and `false` (typescript-eslint#8685) * make the example from the docs work * revert * allow falsey literals on last operand
PR Checklist
Overview
In #8659, we see that the example in the docs for
prefer-optional-chain
:allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing
is not reporting an error.The root cause is actually unrelated to
allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing
— it is becausefoo.bar
is of typeboolean
.In the rule, there is a bypass to avoid flagging unions with falsy members, such as
since changing that to an optional chain would cause a TS error.
However, if the falsy literal is the last operand, then we should report it. This is the change made by this PR.