Skip to content

Commit f1c3b18

Browse files
authored
fix(eslint-plugin): [unbound-method] false positive on property function initializer (typescript-eslint#1890)
1 parent 795fd1c commit f1c3b18

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ function isDangerousMethod(symbol: ts.Symbol, ignoreStatic: boolean): boolean {
198198
}
199199

200200
switch (valueDeclaration.kind) {
201+
case ts.SyntaxKind.PropertyDeclaration:
202+
return (
203+
(valueDeclaration as ts.PropertyDeclaration).initializer?.kind ===
204+
ts.SyntaxKind.FunctionExpression
205+
);
201206
case ts.SyntaxKind.MethodDeclaration:
202207
case ts.SyntaxKind.MethodSignature:
203208
return !(

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,5 +367,19 @@ instance.unbound = x; // THIS SHOULD NOT
367367
},
368368
],
369369
},
370+
{
371+
code: `
372+
class Foo {
373+
unbound = function() {};
374+
}
375+
const unbound = new Foo().unbound;
376+
`,
377+
errors: [
378+
{
379+
line: 5,
380+
messageId: 'unbound',
381+
},
382+
],
383+
},
370384
],
371385
});

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