1
1
import * as Lint from "tslint/lib/lint" ;
2
2
import * as ts from "typescript" ;
3
3
4
-
5
4
export class Rule extends Lint . Rules . AbstractRule {
6
5
public static FAILURE_STRING_FACTORY = ( identifier : string ) => `Identifier '${ identifier } ' never appears on the LHS of an assignment - use const instead of let for its declaration.` ;
7
6
@@ -64,7 +63,7 @@ interface DeclarationUsages {
64
63
}
65
64
66
65
class PreferConstWalker extends Lint . RuleWalker {
67
- private inScopeLetDeclarations : ts . Map < DeclarationUsages > [ ] = [ ] ;
66
+ private inScopeLetDeclarations : ts . MapLike < DeclarationUsages > [ ] = [ ] ;
68
67
private errors : Lint . RuleFailure [ ] = [ ] ;
69
68
private markAssignment ( identifier : ts . Identifier ) {
70
69
const name = identifier . text ;
@@ -172,7 +171,7 @@ class PreferConstWalker extends Lint.RuleWalker {
172
171
}
173
172
174
173
private visitAnyForStatement ( node : ts . ForOfStatement | ts . ForInStatement ) {
175
- const names : ts . Map < DeclarationUsages > = { } ;
174
+ const names : ts . MapLike < DeclarationUsages > = { } ;
176
175
if ( isLet ( node . initializer ) ) {
177
176
if ( node . initializer . kind === ts . SyntaxKind . VariableDeclarationList ) {
178
177
this . collectLetIdentifiers ( node . initializer as ts . VariableDeclarationList , names ) ;
@@ -194,7 +193,7 @@ class PreferConstWalker extends Lint.RuleWalker {
194
193
}
195
194
196
195
visitBlock ( node : ts . Block ) {
197
- const names : ts . Map < DeclarationUsages > = { } ;
196
+ const names : ts . MapLike < DeclarationUsages > = { } ;
198
197
for ( const statement of node . statements ) {
199
198
if ( statement . kind === ts . SyntaxKind . VariableStatement ) {
200
199
this . collectLetIdentifiers ( ( statement as ts . VariableStatement ) . declarationList , names ) ;
@@ -205,15 +204,15 @@ class PreferConstWalker extends Lint.RuleWalker {
205
204
this . popDeclarations ( ) ;
206
205
}
207
206
208
- private collectLetIdentifiers ( list : ts . VariableDeclarationList , ret : ts . Map < DeclarationUsages > ) {
207
+ private collectLetIdentifiers ( list : ts . VariableDeclarationList , ret : ts . MapLike < DeclarationUsages > ) {
209
208
for ( const node of list . declarations ) {
210
209
if ( isLet ( node ) && ! isExported ( node ) ) {
211
210
this . collectNameIdentifiers ( node , node . name , ret ) ;
212
211
}
213
212
}
214
213
}
215
214
216
- private collectNameIdentifiers ( declaration : ts . VariableDeclaration , node : ts . Identifier | ts . BindingPattern , table : ts . Map < DeclarationUsages > ) {
215
+ private collectNameIdentifiers ( declaration : ts . VariableDeclaration , node : ts . Identifier | ts . BindingPattern , table : ts . MapLike < DeclarationUsages > ) {
217
216
if ( node . kind === ts . SyntaxKind . Identifier ) {
218
217
table [ ( node as ts . Identifier ) . text ] = { declaration, usages : 0 } ;
219
218
}
@@ -222,7 +221,7 @@ class PreferConstWalker extends Lint.RuleWalker {
222
221
}
223
222
}
224
223
225
- private collectBindingPatternIdentifiers ( value : ts . VariableDeclaration , pattern : ts . BindingPattern , table : ts . Map < DeclarationUsages > ) {
224
+ private collectBindingPatternIdentifiers ( value : ts . VariableDeclaration , pattern : ts . BindingPattern , table : ts . MapLike < DeclarationUsages > ) {
226
225
for ( const element of pattern . elements ) {
227
226
this . collectNameIdentifiers ( value , element . name , table ) ;
228
227
}
0 commit comments