Skip to content

Commit 8329498

Browse files
authored
feat(eslint-plugin): [no-this-alias] report on assignment expressions (#4718)
1 parent 790a1ee commit 8329498

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Diff for: packages/eslint-plugin/src/rules/no-this-alias.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ export default util.createRule<Options, MessageIds>({
4848
],
4949
create(context, [{ allowDestructuring, allowedNames }]) {
5050
return {
51-
"VariableDeclarator[init.type='ThisExpression']"(
52-
node: TSESTree.VariableDeclarator,
51+
"VariableDeclarator[init.type='ThisExpression'], AssignmentExpression[right.type='ThisExpression']"(
52+
node: TSESTree.VariableDeclarator | TSESTree.AssignmentExpression,
5353
): void {
54-
const { id } = node;
55-
54+
const id =
55+
node.type === AST_NODE_TYPES.VariableDeclarator ? node.id : node.left;
5656
if (allowDestructuring && id.type !== AST_NODE_TYPES.Identifier) {
5757
return;
5858
}

Diff for: packages/eslint-plugin/tests/rules/no-this-alias.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ declare module 'foo' {
6666
code: 'const self = this;',
6767
errors: [idError],
6868
},
69+
{
70+
code: `
71+
let that;
72+
that = this;
73+
`,
74+
errors: [idError],
75+
},
6976
{
7077
code: 'const { props, state } = this;',
7178
options: [

0 commit comments

Comments
 (0)