Skip to content

Commit 27a60e4

Browse files
committed
fix linting errors
1 parent 603ba89 commit 27a60e4

26 files changed

+112
-86
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ namespace ts {
283283
// Parameters with names are handled at the top of this function. Parameters
284284
// without names can only come from JSDocFunctionTypes.
285285
Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType);
286-
let functionType = <JSDocFunctionType>node.parent;
287-
let index = indexOf(functionType.parameters, node);
286+
const functionType = <JSDocFunctionType>node.parent;
287+
const index = indexOf(functionType.parameters, node);
288288
return "arg" + index;
289289
case SyntaxKind.JSDocTypedefTag:
290290
const parentNode = node.parent && node.parent.parent;

src/compiler/checker.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5019,7 +5019,8 @@ namespace ts {
50195019
// If this is a JSDoc construct signature, then skip the first parameter in the
50205020
// parameter list. The first parameter represents the return type of the construct
50215021
// signature.
5022-
for (let i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) {
5022+
const n = declaration.parameters.length;
5023+
for (let i = isJSConstructSignature ? 1 : 0; i < n; i++) {
50235024
const param = declaration.parameters[i];
50245025

50255026
let paramSymbol = param.symbol;
@@ -5118,7 +5119,8 @@ namespace ts {
51185119
function getSignaturesOfSymbol(symbol: Symbol): Signature[] {
51195120
if (!symbol) return emptyArray;
51205121
const result: Signature[] = [];
5121-
for (let i = 0, len = symbol.declarations.length; i < len; i++) {
5122+
const len = symbol.declarations.length;
5123+
for (let i = 0; i < len; i++) {
51225124
const node = symbol.declarations[i];
51235125
switch (node.kind) {
51245126
case SyntaxKind.FunctionType:
@@ -5768,8 +5770,8 @@ namespace ts {
57685770
}
57695771

57705772
function isSubtypeOfAny(candidate: Type, types: Type[]): boolean {
5771-
for (let i = 0, len = types.length; i < len; i++) {
5772-
if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) {
5773+
for (const type of types) {
5774+
if (candidate !== type && isTypeSubtypeOf(candidate, type)) {
57735775
return true;
57745776
}
57755777
}
@@ -7911,7 +7913,8 @@ namespace ts {
79117913
return Ternary.False;
79127914
}
79137915
let result = Ternary.True;
7914-
for (let i = 0, len = sourceSignatures.length; i < len; i++) {
7916+
const len = sourceSignatures.length;
7917+
for (let i = 0; i < len; i++) {
79157918
const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
79167919
if (!related) {
79177920
return Ternary.False;
@@ -18044,7 +18047,8 @@ namespace ts {
1804418047
/** Check each type parameter and check that type parameters have no duplicate type parameter declarations */
1804518048
function checkTypeParameters(typeParameterDeclarations: TypeParameterDeclaration[]) {
1804618049
if (typeParameterDeclarations) {
18047-
for (let i = 0, n = typeParameterDeclarations.length; i < n; i++) {
18050+
const n = typeParameterDeclarations.length;
18051+
for (let i = 0; i < n; i++) {
1804818052
const node = typeParameterDeclarations[i];
1804918053
checkTypeParameter(node);
1805018054

@@ -18324,7 +18328,8 @@ namespace ts {
1832418328
// TypeScript 1.0 spec (April 2014):
1832518329
// When a generic interface has multiple declarations, all declarations must have identical type parameter
1832618330
// lists, i.e. identical type parameter names with identical constraints in identical order.
18327-
for (let i = 0, len = list1.length; i < len; i++) {
18331+
const len = list1.length;
18332+
for (let i = 0; i < len; i++) {
1832818333
const tp1 = list1[i];
1832918334
const tp2 = list2[i];
1833018335
if (tp1.name.text !== tp2.name.text) {
@@ -20761,7 +20766,7 @@ namespace ts {
2076120766
case SyntaxKind.PublicKeyword:
2076220767
case SyntaxKind.ProtectedKeyword:
2076320768
case SyntaxKind.PrivateKeyword:
20764-
let text = visibilityToString(modifierToFlag(modifier.kind));
20769+
const text = visibilityToString(modifierToFlag(modifier.kind));
2076520770

2076620771
if (modifier.kind === SyntaxKind.ProtectedKeyword) {
2076720772
lastProtected = modifier;

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ namespace ts {
620620
break;
621621
case "boolean":
622622
// boolean flag has optional value true, false, others
623-
let optValue = args[i];
623+
const optValue = args[i];
624624
options[opt.name] = optValue !== "false";
625625
// consume next argument as boolean flag value
626626
if (optValue === "false" || optValue === "true") {
@@ -778,7 +778,7 @@ namespace ts {
778778
break;
779779
default:
780780
const value = options[name];
781-
let optionDefinition = optionsNameMap[name.toLowerCase()];
781+
const optionDefinition = optionsNameMap[name.toLowerCase()];
782782
if (optionDefinition) {
783783
const customTypeMap = getCustomTypeMapOfCommandLineOption(optionDefinition);
784784
if (!customTypeMap) {

src/compiler/core.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ namespace ts {
119119
*/
120120
export function forEach<T, U>(array: T[] | undefined, callback: (element: T, index: number) => U | undefined): U | undefined {
121121
if (array) {
122-
for (let i = 0, len = array.length; i < len; i++) {
122+
const len = array.length;
123+
for (let i = 0; i < len; i++) {
123124
const result = callback(array[i], i);
124125
if (result) {
125126
return result;
@@ -143,7 +144,8 @@ namespace ts {
143144
*/
144145
export function every<T>(array: T[], callback: (element: T, index: number) => boolean): boolean {
145146
if (array) {
146-
for (let i = 0, len = array.length; i < len; i++) {
147+
const len = array.length;
148+
for (let i = 0; i < len; i++) {
147149
if (!callback(array[i], i)) {
148150
return false;
149151
}
@@ -155,7 +157,8 @@ namespace ts {
155157

156158
/** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */
157159
export function find<T>(array: T[], predicate: (element: T, index: number) => boolean): T | undefined {
158-
for (let i = 0, len = array.length; i < len; i++) {
160+
const len = array.length;
161+
for (let i = 0; i < len; i++) {
159162
const value = array[i];
160163
if (predicate(value, i)) {
161164
return value;
@@ -169,7 +172,8 @@ namespace ts {
169172
* This is like `forEach`, but never returns undefined.
170173
*/
171174
export function findMap<T, U>(array: T[], callback: (element: T, index: number) => U | undefined): U {
172-
for (let i = 0, len = array.length; i < len; i++) {
175+
const len = array.length;
176+
for (let i = 0; i < len; i++) {
173177
const result = callback(array[i], i);
174178
if (result) {
175179
return result;
@@ -191,7 +195,8 @@ namespace ts {
191195

192196
export function indexOf<T>(array: T[], value: T): number {
193197
if (array) {
194-
for (let i = 0, len = array.length; i < len; i++) {
198+
const len = array.length;
199+
for (let i = 0; i < len; i++) {
195200
if (array[i] === value) {
196201
return i;
197202
}
@@ -201,7 +206,8 @@ namespace ts {
201206
}
202207

203208
export function indexOfAnyCharCode(text: string, charCodes: number[], start?: number): number {
204-
for (let i = start || 0, len = text.length; i < len; i++) {
209+
const len = text.length;
210+
for (let i = start || 0; i < len; i++) {
205211
if (contains(charCodes, text.charCodeAt(i))) {
206212
return i;
207213
}

src/compiler/parser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,8 +1678,8 @@ namespace ts {
16781678
// Method declarations are not necessarily reusable. An object-literal
16791679
// may have a method calls "constructor(...)" and we must reparse that
16801680
// into an actual .ConstructorDeclaration.
1681-
let methodDeclaration = <MethodDeclaration>node;
1682-
let nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier &&
1681+
const methodDeclaration = <MethodDeclaration>node;
1682+
const nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier &&
16831683
(<Identifier>methodDeclaration.name).originalKeywordKind === SyntaxKind.ConstructorKeyword;
16841684

16851685
return !nameIsConstructor;
@@ -7404,7 +7404,8 @@ namespace ts {
74047404
if (position >= array.pos && position < array.end) {
74057405
// position was in this array. Search through this array to see if we find a
74067406
// viable element.
7407-
for (let i = 0, n = array.length; i < n; i++) {
7407+
const n = array.length;
7408+
for (let i = 0; i < n; i++) {
74087409
const child = array[i];
74097410
if (child) {
74107411
if (child.pos === position) {

src/compiler/program.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ namespace ts {
4040
return;
4141
}
4242

43-
for (let i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) {
43+
const n = Math.min(commonPathComponents.length, sourcePathComponents.length);
44+
for (let i = 0; i < n; i++) {
4445
if (getCanonicalFileName(commonPathComponents[i]) !== getCanonicalFileName(sourcePathComponents[i])) {
4546
if (i === 0) {
4647
// Failed to find any common path component
@@ -695,7 +696,8 @@ namespace ts {
695696
}
696697

697698
// update fileName -> file mapping
698-
for (let i = 0, len = newSourceFiles.length; i < len; i++) {
699+
const len = newSourceFiles.length;
700+
for (let i = 0; i < len; i++) {
699701
filesByName.set(filePaths[i], newSourceFiles[i]);
700702
}
701703

@@ -952,7 +954,7 @@ namespace ts {
952954
}
953955
break;
954956
case SyntaxKind.HeritageClause:
955-
let heritageClause = <HeritageClause>node;
957+
const heritageClause = <HeritageClause>node;
956958
if (heritageClause.token === SyntaxKind.ImplementsKeyword) {
957959
diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file));
958960
return;
@@ -971,7 +973,7 @@ namespace ts {
971973
diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file));
972974
return;
973975
case SyntaxKind.TypeAssertionExpression:
974-
let typeAssertionExpression = <TypeAssertion>node;
976+
const typeAssertionExpression = <TypeAssertion>node;
975977
diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file));
976978
return;
977979
}
@@ -1170,7 +1172,7 @@ namespace ts {
11701172
case SyntaxKind.ImportDeclaration:
11711173
case SyntaxKind.ImportEqualsDeclaration:
11721174
case SyntaxKind.ExportDeclaration:
1173-
let moduleNameExpr = getExternalModuleName(node);
1175+
const moduleNameExpr = getExternalModuleName(node);
11741176
if (!moduleNameExpr || moduleNameExpr.kind !== SyntaxKind.StringLiteral) {
11751177
break;
11761178
}

src/compiler/scanner.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ namespace ts {
531531
const ch = text.charCodeAt(pos);
532532

533533
if ((pos + mergeConflictMarkerLength) < text.length) {
534-
for (let i = 0, n = mergeConflictMarkerLength; i < n; i++) {
534+
for (let i = 0; i < mergeConflictMarkerLength; i++) {
535535
if (text.charCodeAt(pos + i) !== ch) {
536536
return false;
537537
}
@@ -643,7 +643,7 @@ namespace ts {
643643
pos++;
644644
continue;
645645
case CharacterCodes.slash:
646-
let nextChar = text.charCodeAt(pos + 1);
646+
const nextChar = text.charCodeAt(pos + 1);
647647
let hasTrailingNewLine = false;
648648
if (nextChar === CharacterCodes.slash || nextChar === CharacterCodes.asterisk) {
649649
const kind = nextChar === CharacterCodes.slash ? SyntaxKind.SingleLineCommentTrivia : SyntaxKind.MultiLineCommentTrivia;
@@ -766,7 +766,8 @@ namespace ts {
766766
return false;
767767
}
768768

769-
for (let i = 1, n = name.length; i < n; i++) {
769+
const n = name.length;
770+
for (let i = 1; i < n; i++) {
770771
if (!isIdentifierPart(name.charCodeAt(i), languageVersion)) {
771772
return false;
772773
}
@@ -1563,7 +1564,7 @@ namespace ts {
15631564
pos++;
15641565
return token = SyntaxKind.AtToken;
15651566
case CharacterCodes.backslash:
1566-
let cookedChar = peekUnicodeEscape();
1567+
const cookedChar = peekUnicodeEscape();
15671568
if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) {
15681569
pos += 6;
15691570
tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();

src/compiler/sys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ namespace ts {
160160

161161
function getNames(collection: any): string[] {
162162
const result: string[] = [];
163-
for (let e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
163+
for (const e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
164164
result.push(e.item().Name);
165165
}
166166
return result.sort();

src/compiler/utilities.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ namespace ts {
550550
let errorNode = node;
551551
switch (node.kind) {
552552
case SyntaxKind.SourceFile:
553-
let pos = skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
553+
const pos = skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
554554
if (pos === sourceFile.text.length) {
555555
// file is empty - return span for the beginning of the file
556556
return createTextSpan(0, 0);
@@ -682,7 +682,7 @@ namespace ts {
682682
case SyntaxKind.QualifiedName:
683683
case SyntaxKind.PropertyAccessExpression:
684684
case SyntaxKind.ThisKeyword:
685-
let parent = node.parent;
685+
const parent = node.parent;
686686
if (parent.kind === SyntaxKind.TypeQuery) {
687687
return false;
688688
}
@@ -770,7 +770,7 @@ namespace ts {
770770
switch (node.kind) {
771771
case SyntaxKind.YieldExpression:
772772
visitor(<YieldExpression>node);
773-
let operand = (<YieldExpression>node).expression;
773+
const operand = (<YieldExpression>node).expression;
774774
if (operand) {
775775
traverse(operand);
776776
}
@@ -1222,7 +1222,7 @@ namespace ts {
12221222
case SyntaxKind.NumericLiteral:
12231223
case SyntaxKind.StringLiteral:
12241224
case SyntaxKind.ThisKeyword:
1225-
let parent = node.parent;
1225+
const parent = node.parent;
12261226
switch (parent.kind) {
12271227
case SyntaxKind.VariableDeclaration:
12281228
case SyntaxKind.Parameter:
@@ -1244,13 +1244,13 @@ namespace ts {
12441244
case SyntaxKind.SwitchStatement:
12451245
return (<ExpressionStatement>parent).expression === node;
12461246
case SyntaxKind.ForStatement:
1247-
let forStatement = <ForStatement>parent;
1247+
const forStatement = <ForStatement>parent;
12481248
return (forStatement.initializer === node && forStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
12491249
forStatement.condition === node ||
12501250
forStatement.incrementor === node;
12511251
case SyntaxKind.ForInStatement:
12521252
case SyntaxKind.ForOfStatement:
1253-
let forInStatement = <ForInStatement | ForOfStatement>parent;
1253+
const forInStatement = <ForInStatement | ForOfStatement>parent;
12541254
return (forInStatement.initializer === node && forInStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
12551255
forInStatement.expression === node;
12561256
case SyntaxKind.TypeAssertionExpression:

src/harness/harness.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace Utils {
8585
eval(fileContents);
8686
break;
8787
case ExecutionEnvironment.Node:
88-
let vm = require("vm");
88+
const vm = require("vm");
8989
if (nodeContext) {
9090
vm.runInNewContext(fileContents, nodeContext, fileName);
9191
}
@@ -175,9 +175,9 @@ namespace Utils {
175175
assert.isFalse(array.end > node.end, "array.end > node.end");
176176
assert.isFalse(array.pos < currentPos, "array.pos < currentPos");
177177

178-
for (let i = 0, n = array.length; i < n; i++) {
179-
assert.isFalse(array[i].pos < currentPos, "array[i].pos < currentPos");
180-
currentPos = array[i].end;
178+
for (const item of array) {
179+
assert.isFalse(item.pos < currentPos, "array[i].pos < currentPos");
180+
currentPos = item.end;
181181
}
182182

183183
currentPos = array.end;
@@ -344,7 +344,8 @@ namespace Utils {
344344

345345
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
346346

347-
for (let i = 0, n = array1.length; i < n; i++) {
347+
const n = array1.length;
348+
for (let i = 0; i < n; i++) {
348349
const d1 = array1[i];
349350
const d2 = array2[i];
350351

@@ -400,7 +401,8 @@ namespace Utils {
400401
assert.equal(array1.end, array2.end, "array1.end !== array2.end");
401402
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
402403

403-
for (let i = 0, n = array1.length; i < n; i++) {
404+
const n = array1.length;
405+
for (let i = 0; i < n; i++) {
404406
assertStructuralEquals(array1[i], array2[i]);
405407
}
406408
}

0 commit comments

Comments
 (0)