Skip to content

Commit 29a01b8

Browse files
a-tarasyukbradzacher
authored andcommitted
fix(eslint-plugin): [unbound-method] false positive in equality comparisons (typescript-eslint#914)
1 parent 344bafe commit 29a01b8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/eslint-plugin/src/rules/unbound-method.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ function isSafeUse(node: TSESTree.Node): boolean {
123123
case AST_NODE_TYPES.UnaryExpression:
124124
return parent.operator === 'typeof';
125125

126+
case AST_NODE_TYPES.BinaryExpression:
127+
return ['instanceof', '==', '!=', '===', '!=='].includes(parent.operator);
128+
126129
case AST_NODE_TYPES.TSNonNullExpression:
127130
case AST_NODE_TYPES.TSAsExpression:
128131
case AST_NODE_TYPES.TSTypeAssertion:

packages/eslint-plugin/tests/rules/unbound-method.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,27 @@ instance.unbound\`\`;
5252
if (instance.bound) { }
5353
if (instance.unbound) { }
5454
55+
if (instance.bound !== undefined) { }
56+
if (instance.unbound !== undefined) { }
57+
5558
if (ContainsMethods.boundStatic) { }
5659
if (ContainsMethods.unboundStatic) { }
5760
61+
if (ContainsMethods.boundStatic !== undefined) { }
62+
if (ContainsMethods.unboundStatic !== undefined) { }
63+
5864
while (instance.bound) { }
5965
while (instance.unbound) { }
6066
67+
while (instance.bound !== undefined) { }
68+
while (instance.unbound !== undefined) { }
69+
6170
while (ContainsMethods.boundStatic) { }
6271
while (ContainsMethods.unboundStatic) { }
6372
73+
while (ContainsMethods.boundStatic !== undefined) { }
74+
while (ContainsMethods.unboundStatic !== undefined) { }
75+
6476
instance.bound as any;
6577
ContainsMethods.boundStatic as any;
6678

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy