Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(eslint-plugin): [unbound-method] false positives for unary expres…
…sions (#1964)
  • Loading branch information
auhsoja committed May 4, 2020
1 parent f82fd7b commit b35070e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/eslint-plugin/src/rules/unbound-method.ts
Expand Up @@ -241,7 +241,10 @@ function isSafeUse(node: TSESTree.Node): boolean {
return parent.tag === node;

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

case AST_NODE_TYPES.BinaryExpression:
return ['instanceof', '==', '!=', '===', '!=='].includes(parent.operator);
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-plugin/tests/rules/unbound-method.test.ts
Expand Up @@ -150,6 +150,9 @@ ruleTester.run('unbound-method', rule, {

'instance.unbound = () => {};',
'instance.unbound = instance.unbound.bind(instance);',
'if (!!instance.unbound) {}',
'void instance.unbound',
'delete instance.unbound',
].map(addContainsMethodsClass),
`
interface RecordA {
Expand Down

0 comments on commit b35070e

Please sign in to comment.