From 83294989dad543351a26e95be8d11a91d348679a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Garc=C3=ADa?= <82288753+juank1809@users.noreply.github.com> Date: Mon, 28 Mar 2022 19:54:17 -0500 Subject: [PATCH] feat(eslint-plugin): [no-this-alias] report on assignment expressions (#4718) --- packages/eslint-plugin/src/rules/no-this-alias.ts | 8 ++++---- packages/eslint-plugin/tests/rules/no-this-alias.test.ts | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-this-alias.ts b/packages/eslint-plugin/src/rules/no-this-alias.ts index 5c9c9f56881..5750b8209b1 100644 --- a/packages/eslint-plugin/src/rules/no-this-alias.ts +++ b/packages/eslint-plugin/src/rules/no-this-alias.ts @@ -48,11 +48,11 @@ export default util.createRule({ ], create(context, [{ allowDestructuring, allowedNames }]) { return { - "VariableDeclarator[init.type='ThisExpression']"( - node: TSESTree.VariableDeclarator, + "VariableDeclarator[init.type='ThisExpression'], AssignmentExpression[right.type='ThisExpression']"( + node: TSESTree.VariableDeclarator | TSESTree.AssignmentExpression, ): void { - const { id } = node; - + const id = + node.type === AST_NODE_TYPES.VariableDeclarator ? node.id : node.left; if (allowDestructuring && id.type !== AST_NODE_TYPES.Identifier) { return; } diff --git a/packages/eslint-plugin/tests/rules/no-this-alias.test.ts b/packages/eslint-plugin/tests/rules/no-this-alias.test.ts index 0a8f7340bca..0d2832ec2ef 100644 --- a/packages/eslint-plugin/tests/rules/no-this-alias.test.ts +++ b/packages/eslint-plugin/tests/rules/no-this-alias.test.ts @@ -66,6 +66,13 @@ declare module 'foo' { code: 'const self = this;', errors: [idError], }, + { + code: ` +let that; +that = this; + `, + errors: [idError], + }, { code: 'const { props, state } = this;', options: [