11import * as Lint from "tslint/lib/lint" ;
22import * as ts from "typescript" ;
33
4-
54export class Rule extends Lint . Rules . AbstractRule {
65 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.` ;
76
@@ -64,7 +63,7 @@ interface DeclarationUsages {
6463}
6564
6665class PreferConstWalker extends Lint . RuleWalker {
67- private inScopeLetDeclarations : ts . Map < DeclarationUsages > [ ] = [ ] ;
66+ private inScopeLetDeclarations : ts . MapLike < DeclarationUsages > [ ] = [ ] ;
6867 private errors : Lint . RuleFailure [ ] = [ ] ;
6968 private markAssignment ( identifier : ts . Identifier ) {
7069 const name = identifier . text ;
@@ -172,7 +171,7 @@ class PreferConstWalker extends Lint.RuleWalker {
172171 }
173172
174173 private visitAnyForStatement ( node : ts . ForOfStatement | ts . ForInStatement ) {
175- const names : ts . Map < DeclarationUsages > = { } ;
174+ const names : ts . MapLike < DeclarationUsages > = { } ;
176175 if ( isLet ( node . initializer ) ) {
177176 if ( node . initializer . kind === ts . SyntaxKind . VariableDeclarationList ) {
178177 this . collectLetIdentifiers ( node . initializer as ts . VariableDeclarationList , names ) ;
@@ -194,7 +193,7 @@ class PreferConstWalker extends Lint.RuleWalker {
194193 }
195194
196195 visitBlock ( node : ts . Block ) {
197- const names : ts . Map < DeclarationUsages > = { } ;
196+ const names : ts . MapLike < DeclarationUsages > = { } ;
198197 for ( const statement of node . statements ) {
199198 if ( statement . kind === ts . SyntaxKind . VariableStatement ) {
200199 this . collectLetIdentifiers ( ( statement as ts . VariableStatement ) . declarationList , names ) ;
@@ -205,15 +204,15 @@ class PreferConstWalker extends Lint.RuleWalker {
205204 this . popDeclarations ( ) ;
206205 }
207206
208- private collectLetIdentifiers ( list : ts . VariableDeclarationList , ret : ts . Map < DeclarationUsages > ) {
207+ private collectLetIdentifiers ( list : ts . VariableDeclarationList , ret : ts . MapLike < DeclarationUsages > ) {
209208 for ( const node of list . declarations ) {
210209 if ( isLet ( node ) && ! isExported ( node ) ) {
211210 this . collectNameIdentifiers ( node , node . name , ret ) ;
212211 }
213212 }
214213 }
215214
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 > ) {
217216 if ( node . kind === ts . SyntaxKind . Identifier ) {
218217 table [ ( node as ts . Identifier ) . text ] = { declaration, usages : 0 } ;
219218 }
@@ -222,7 +221,7 @@ class PreferConstWalker extends Lint.RuleWalker {
222221 }
223222 }
224223
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 > ) {
226225 for ( const element of pattern . elements ) {
227226 this . collectNameIdentifiers ( value , element . name , table ) ;
228227 }
0 commit comments