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): unbound-method false positive when comparing to null #914

Conversation

a-tarasyuk
Copy link
Contributor

Fixes #877

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @a-tarasyuk!

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

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

Because I haven't used this rule.
One thing I want to confirm about this change is:

BinaryExpression encompasses much more than just equality checks: https://github.com/estree/estree/blob/master/es5.md#binaryexpression

enum BinaryOperator {
    "==" | "!=" | "===" | "!=="
         | "<" | "<=" | ">" | ">="
         | "<<" | ">>" | ">>>"
         | "+" | "-" | "*" | "/" | "%"
         | "|" | "^" | "&" | "in"
         | "instanceof"
}

Are we okay with opening this rule up to "ignore" all of these operators?
If yes, then LGTM. If no, then please add a check for the operator.

@a-tarasyuk
Copy link
Contributor Author

@bradzacher

if (x.y) {}
    ^^^
    MemberExpression -> Parent `IfStatement`

The issue in this case that if we check MemberExpression (!==, ==, etc). a parent doesn't equal to IfStatement, parent equals to BinaryExpression. For that reason I added new type to switch statement to ignore all Member Expressions which have parentBinaryExpressions. On need to check Parent for BinaryExpression not to MemberExpression?


if (x.y !== 1) {}
    ^^^
    MemberExpression -> Parent `BinaryExpression` -> Parent `IfStatement`

@bradzacher
Copy link
Member

Sorry - i meant rather than just saying "having a parent of type BinaryExpression is fine", I was meaning - do we want to limit the scope a little bit.
I.e. "having a parent of BinaryExpression is fine, as long as
['==', '!=', '===', '!==', 'instanceof'].includes(parentBinaryExpression.operator)"

I think this is fine as is though. I don't think any of the other binary operators should cause problems.

@a-tarasyuk a-tarasyuk force-pushed the bug/877-unbound-method-false-positive-when-comparing-to-null branch from 9bfa9fc to 7375663 Compare August 28, 2019 18:11
@a-tarasyuk
Copy link
Contributor Author

@bradzacher oke.

@codecov
Copy link

codecov bot commented Aug 28, 2019

Codecov Report

Merging #914 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #914      +/-   ##
==========================================
+ Coverage   94.07%   94.08%   +<.01%     
==========================================
  Files         113      113              
  Lines        4915     4916       +1     
  Branches     1369     1369              
==========================================
+ Hits         4624     4625       +1     
  Misses        165      165              
  Partials      126      126
Impacted Files Coverage Δ
packages/eslint-plugin/src/rules/unbound-method.ts 97.05% <100%> (+0.08%) ⬆️

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

@bradzacher bradzacher merged commit 29a01b8 into typescript-eslint:master Aug 28, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
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.

[unbound-method] False positive when comparing to null
2 participants