Skip to content

Commit b35070e

Browse files
authored
fix(eslint-plugin): [unbound-method] false positives for unary expressions (#1964)
1 parent f82fd7b commit b35070e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Diff for: packages/eslint-plugin/src/rules/unbound-method.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ function isSafeUse(node: TSESTree.Node): boolean {
241241
return parent.tag === node;
242242

243243
case AST_NODE_TYPES.UnaryExpression:
244-
return parent.operator === 'typeof';
244+
// the first case is safe for obvious
245+
// reasons. The second one is also fine
246+
// since we're returning something falsy
247+
return ['typeof', '!', 'void', 'delete'].includes(parent.operator);
245248

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

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

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ ruleTester.run('unbound-method', rule, {
150150

151151
'instance.unbound = () => {};',
152152
'instance.unbound = instance.unbound.bind(instance);',
153+
'if (!!instance.unbound) {}',
154+
'void instance.unbound',
155+
'delete instance.unbound',
153156
].map(addContainsMethodsClass),
154157
`
155158
interface RecordA {

0 commit comments

Comments
 (0)