Skip to content
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

Merged
merged 1 commit into from May 30, 2020
Merged

fix(eslint-plugin): [no-unnecessary-condition] handle comparison of any, unknown and loose comparisons with nullish values #2123

merged 1 commit into from May 30, 2020

Conversation

avocadowastaken
Copy link
Contributor

, unknown and nullish values (closes #2113)

@typescript-eslint
Copy link
Contributor

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,
Copy link
Contributor Author

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.

@codecov
Copy link

codecov bot commented May 28, 2020

Codecov Report

Merging #2123 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            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     
Flag Coverage Δ
#unittest 93.44% <100.00%> (+0.02%) ⬆️
Impacted Files Coverage Δ
...slint-plugin/src/rules/no-unnecessary-condition.ts 96.96% <100.00%> (ø)
packages/eslint-plugin/src/util/types.ts 82.42% <0.00%> (+1.21%) ⬆️

@bradzacher bradzacher added the bug Something isn't working label May 28, 2020
Copy link
Member

@bradzacher bradzacher left a 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!

@bradzacher bradzacher changed the title fix(eslint-plugin): [no-unnecessary-condition] Handle comparison of any… fix(eslint-plugin): [no-unnecessary-condition] handle comparison of any, unknown and loose comparisons with nullish values May 30, 2020
@bradzacher bradzacher merged commit 1ae1d01 into typescript-eslint:master May 30, 2020
@avocadowastaken avocadowastaken deleted the no-unnecessart-condition-with-unknown-any-and-nullish branch May 31, 2020 00:39
if (
(leftType.flags === UNDEFINED &&
!typeContainsFlag(rightType, UNDEFINED)) ||
!isTypeFlagSet(rightType, UNDEFINED, true)) ||
Copy link
Contributor

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) {}
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-unnecessary-condition] == null against optional method param no longer allowed
3 participants