-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [no-unnecessary-condition] handle comparison of any, unknown and loose comparisons with nullish values #2123
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): [no-unnecessary-condition] handle comparison of any, unknown and loose comparisons with nullish values #2123
Conversation
Thanks for the PR, @umidbekkarimov! 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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
@@ -14,6 +13,7 @@ import { | |||
isStrictCompilerOptionEnabled, | |||
} from 'tsutils'; | |||
import { | |||
isTypeFlagSet, |
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.
I needed that to have access to isReceiver
option.
, unknown and nullish values
Codecov Report
@@ Coverage Diff @@
## master #2123 +/- ##
==========================================
+ Coverage 93.42% 93.44% +0.02%
==========================================
Files 171 171
Lines 7755 7755
Branches 2215 2217 +2
==========================================
+ Hits 7245 7247 +2
+ Misses 244 243 -1
+ Partials 266 265 -1
|
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.
LGTM - thanks for doing this!
if ( | ||
(leftType.flags === UNDEFINED && | ||
!typeContainsFlag(rightType, UNDEFINED)) || | ||
!isTypeFlagSet(rightType, UNDEFINED, true)) || |
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.
It's niche, but we might want similar "NULLISH" handling for the == undefined
case, otherwise the error will false positive on code like:
function foo(x: string | null) {
if(x == undefined) {}
}
, unknown and nullish values (closes #2113)