Skip to content

Commit

Permalink
fix(eslint-plugin): [unbound-method] false positive on property funct…
Browse files Browse the repository at this point in the history
…ion initializer (#1890)
  • Loading branch information
vapurrmaid committed Apr 13, 2020
1 parent 795fd1c commit f1c3b18
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/eslint-plugin/src/rules/unbound-method.ts
Expand Up @@ -198,6 +198,11 @@ function isDangerousMethod(symbol: ts.Symbol, ignoreStatic: boolean): boolean {
}

switch (valueDeclaration.kind) {
case ts.SyntaxKind.PropertyDeclaration:
return (
(valueDeclaration as ts.PropertyDeclaration).initializer?.kind ===
ts.SyntaxKind.FunctionExpression
);
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.MethodSignature:
return !(
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-plugin/tests/rules/unbound-method.test.ts
Expand Up @@ -367,5 +367,19 @@ instance.unbound = x; // THIS SHOULD NOT
},
],
},
{
code: `
class Foo {
unbound = function() {};
}
const unbound = new Foo().unbound;
`,
errors: [
{
line: 5,
messageId: 'unbound',
},
],
},
],
});

0 comments on commit f1c3b18

Please sign in to comment.