Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2bdf81

Browse files
anikethsahaarmano2
authored andcommitted
chore: ignores super methods
1 parent 4615048 commit d2bdf81

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ function isSafeUse(node: TSESTree.Node): boolean {
305305
return ['instanceof', '==', '!=', '===', '!=='].includes(parent.operator);
306306

307307
case AST_NODE_TYPES.AssignmentExpression:
308-
return parent.operator === '=' && node === parent.left;
308+
return (
309+
parent.operator === '=' &&
310+
(node === parent.left || node.object.type === AST_NODE_TYPES.Super)
311+
);
309312

310313
case AST_NODE_TYPES.ChainExpression:
311314
case AST_NODE_TYPES.TSNonNullExpression:

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ ruleTester.run('unbound-method', rule, {
5454
"['1', '2', '3'].map(Number.parseInt);",
5555
'[5.2, 7.1, 3.6].map(Math.floor);',
5656
'const x = console.log;',
57+
`
58+
class BaseClass {
59+
x: number = 42;
60+
logThis() {
61+
console.log('x is ');
62+
}
63+
}
64+
65+
class OtherClass extends BaseClass {
66+
superLogThis: any;
67+
constructor() {
68+
super();
69+
this.superLogThis = super.logThis; // X - Incorrect eslint error
70+
}
71+
}
72+
73+
const oc = new OtherClass();
74+
oc.superLogThis();
75+
`,
5776
...[
5877
'instance.bound();',
5978
'instance.unbound();',

0 commit comments

Comments
 (0)