Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit c9d2227

Browse files
authored
[FIX] [no-this-alias] prevent crashes from declare statements (#282)
1 parent 4245290 commit c9d2227

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

lib/rules/no-this-alias.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ module.exports = {
5959
)[0];
6060

6161
return {
62-
VariableDeclarator(node) {
63-
const { id, init } = node;
62+
"VariableDeclarator[init.type='ThisExpression']"(node) {
63+
const { id } = node;
6464

65-
if (init.type !== "ThisExpression") return;
66-
if (allowDestructuring && node.id.type !== "Identifier") return;
65+
if (allowDestructuring && id.type !== "Identifier") return;
6766

6867
if (!allowedNames.includes(id.name)) {
6968
context.report({

tests/lib/rules/no-this-alias.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ const [foo, bar] = this;
5555
},
5656
],
5757
},
58+
// https://github.com/bradzacher/eslint-plugin-typescript/issues/281
59+
`
60+
declare module 'foo' {
61+
declare const aVar: string
62+
}
63+
`,
5864
],
5965

6066
invalid: [

0 commit comments

Comments
 (0)