Skip to content

Commit 29a01b8

Browse files
a-tarasyukbradzacher
authored andcommitted
fix(eslint-plugin): [unbound-method] false positive in equality comparisons (#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

+3
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

+12
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)