Skip to content

Commit

Permalink
Merge 1a24d0c into 4615048
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 8, 2021
2 parents 4615048 + 1a24d0c commit 63afcc3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/eslint-plugin/src/rules/unbound-method.ts
Expand Up @@ -305,7 +305,14 @@ function isSafeUse(node: TSESTree.Node): boolean {
return ['instanceof', '==', '!=', '===', '!=='].includes(parent.operator);

case AST_NODE_TYPES.AssignmentExpression:
return parent.operator === '=' && node === parent.left;
return (
parent.operator === '=' &&
(node === parent.left ||
(node.type === AST_NODE_TYPES.MemberExpression &&
node.object.type === AST_NODE_TYPES.Super &&
parent.left.type === AST_NODE_TYPES.MemberExpression &&
parent.left.object.type === AST_NODE_TYPES.ThisExpression))
);

case AST_NODE_TYPES.ChainExpression:
case AST_NODE_TYPES.TSNonNullExpression:
Expand Down
59 changes: 59 additions & 0 deletions packages/eslint-plugin/tests/rules/unbound-method.test.ts
Expand Up @@ -265,6 +265,22 @@ class Foo {
}
const { bound } = new Foo();
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/1866
`
class BaseClass {
x: number = 42;
logThis() {}
}
class OtherClass extends BaseClass {
superLogThis: any;
constructor() {
super();
this.superLogThis = super.logThis;
}
}
const oc = new OtherClass();
oc.superLogThis();
`,
],
invalid: [
{
Expand Down Expand Up @@ -529,5 +545,48 @@ const { log } = console;
},
],
},
// https://github.com/typescript-eslint/typescript-eslint/issues/1866
{
code: `
class BaseClass {
logThis() {}
}
class OtherClass extends BaseClass {
constructor() {
super();
const x = super.logThis;
}
}
`,
errors: [
{
line: 8,
column: 15,
messageId: 'unbound',
},
],
},
// https://github.com/typescript-eslint/typescript-eslint/issues/1866
{
code: `
class BaseClass {
logThis() {}
}
class OtherClass extends BaseClass {
constructor() {
super();
let x;
x = super.logThis;
}
}
`,
errors: [
{
line: 9,
column: 9,
messageId: 'unbound',
},
],
},
],
});

0 comments on commit 63afcc3

Please sign in to comment.