Skip to content

Commit

Permalink
feat(eslint-plugin): [no-this-alias] report on assignment expressions (
Browse files Browse the repository at this point in the history
  • Loading branch information
juank1809 committed Mar 29, 2022
1 parent 790a1ee commit 8329498
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/eslint-plugin/src/rules/no-this-alias.ts
Expand Up @@ -48,11 +48,11 @@ export default util.createRule<Options, MessageIds>({
],
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;
}
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-plugin/tests/rules/no-this-alias.test.ts
Expand Up @@ -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: [
Expand Down

0 comments on commit 8329498

Please sign in to comment.