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: [