Navigation Menu

Skip to content

Commit

Permalink
fix(eslint-plugin): [unbound-method] false positive in equality compa…
Browse files Browse the repository at this point in the history
…risons (#914)
  • Loading branch information
a-tarasyuk authored and bradzacher committed Aug 28, 2019
1 parent 344bafe commit 29a01b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/eslint-plugin/src/rules/unbound-method.ts
Expand Up @@ -123,6 +123,9 @@ function isSafeUse(node: TSESTree.Node): boolean {
case AST_NODE_TYPES.UnaryExpression:
return parent.operator === 'typeof';

case AST_NODE_TYPES.BinaryExpression:
return ['instanceof', '==', '!=', '===', '!=='].includes(parent.operator);

case AST_NODE_TYPES.TSNonNullExpression:
case AST_NODE_TYPES.TSAsExpression:
case AST_NODE_TYPES.TSTypeAssertion:
Expand Down
12 changes: 12 additions & 0 deletions packages/eslint-plugin/tests/rules/unbound-method.test.ts
Expand Up @@ -52,15 +52,27 @@ instance.unbound\`\`;
if (instance.bound) { }
if (instance.unbound) { }
if (instance.bound !== undefined) { }
if (instance.unbound !== undefined) { }
if (ContainsMethods.boundStatic) { }
if (ContainsMethods.unboundStatic) { }
if (ContainsMethods.boundStatic !== undefined) { }
if (ContainsMethods.unboundStatic !== undefined) { }
while (instance.bound) { }
while (instance.unbound) { }
while (instance.bound !== undefined) { }
while (instance.unbound !== undefined) { }
while (ContainsMethods.boundStatic) { }
while (ContainsMethods.unboundStatic) { }
while (ContainsMethods.boundStatic !== undefined) { }
while (ContainsMethods.unboundStatic !== undefined) { }
instance.bound as any;
ContainsMethods.boundStatic as any;
Expand Down

0 comments on commit 29a01b8

Please sign in to comment.