Skip to content

Commit d998e97

Browse files
author
Andy
authored
Apply 'prefer-for-of' tslint rule (microsoft#19721)
1 parent 8b5d856 commit d998e97

15 files changed

Lines changed: 32 additions & 47 deletions

File tree

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,8 +2854,7 @@ namespace ts {
28542854
function mapToTypeNodes(types: Type[], context: NodeBuilderContext): TypeNode[] {
28552855
if (some(types)) {
28562856
const result = [];
2857-
for (let i = 0; i < types.length; ++i) {
2858-
const type = types[i];
2857+
for (const type of types) {
28592858
const typeNode = typeToTypeNodeHelper(type, context);
28602859
if (typeNode) {
28612860
result.push(typeNode);

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,8 +2661,8 @@ namespace ts {
26612661
function writeLines(text: string): void {
26622662
const lines = text.split(/\r\n?|\n/g);
26632663
const indentation = guessIndentation(lines);
2664-
for (let i = 0; i < lines.length; i++) {
2665-
const line = indentation ? lines[i].slice(indentation) : lines[i];
2664+
for (const lineText of lines) {
2665+
const line = indentation ? lineText.slice(indentation) : lineText;
26662666
if (line.length) {
26672667
writeLine();
26682668
write(line);

src/compiler/transformers/module/system.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ namespace ts {
146146
function collectDependencyGroups(externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]) {
147147
const groupIndices = createMap<number>();
148148
const dependencyGroups: DependencyGroup[] = [];
149-
for (let i = 0; i < externalImports.length; i++) {
150-
const externalImport = externalImports[i];
149+
for (const externalImport of externalImports) {
151150
const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions);
152151
if (externalModuleName) {
153152
const text = externalModuleName.text;

src/compiler/tsc.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ namespace ts {
305305

306306
const optionsDescriptionMap = createMap<string[]>(); // Map between option.description and list of option.type if it is a kind
307307

308-
for (let i = 0; i < optsList.length; i++) {
309-
const option = optsList[i];
310-
308+
for (const option of optsList) {
311309
// If an option lacks a description,
312310
// it is not officially supported.
313311
if (!option.description) {

src/harness/compilerRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ class CompilerBaselineRunner extends RunnerBase {
211211
this.emit = false;
212212

213213
const opts = this.options.split(",");
214-
for (let i = 0; i < opts.length; i++) {
215-
switch (opts[i]) {
214+
for (const opt of opts) {
215+
switch (opt) {
216216
case "emit":
217217
this.emit = true;
218218
break;

src/harness/harness.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,13 @@ namespace Harness {
575575
function filesInFolder(folder: string): string[] {
576576
let paths: string[] = [];
577577

578-
const files = fs.readdirSync(folder);
579-
for (let i = 0; i < files.length; i++) {
580-
const pathToFile = pathModule.join(folder, files[i]);
578+
for (const file of fs.readdirSync(folder)) {
579+
const pathToFile = pathModule.join(folder, file);
581580
const stat = fs.statSync(pathToFile);
582581
if (options.recursive && stat.isDirectory()) {
583582
paths = paths.concat(filesInFolder(pathToFile));
584583
}
585-
else if (stat.isFile() && (!spec || files[i].match(spec))) {
584+
else if (stat.isFile() && (!spec || file.match(spec))) {
586585
paths.push(pathToFile);
587586
}
588587
}
@@ -1581,10 +1580,8 @@ namespace Harness {
15811580

15821581
// Preserve legacy behavior
15831582
if (lastIndexWritten === undefined) {
1584-
for (let i = 0; i < codeLines.length; i++) {
1585-
const currentCodeLine = codeLines[i];
1586-
typeLines += currentCodeLine + "\r\n";
1587-
typeLines += "No type information for this code.";
1583+
for (const codeLine of codeLines) {
1584+
typeLines += codeLine + "\r\nNo type information for this code.";
15881585
}
15891586
}
15901587
else {
@@ -1870,8 +1867,7 @@ namespace Harness {
18701867
let currentFileName: any = undefined;
18711868
let refs: string[] = [];
18721869

1873-
for (let i = 0; i < lines.length; i++) {
1874-
const line = lines[i];
1870+
for (const line of lines) {
18751871
const testMetaData = optionRegex.exec(line);
18761872
if (testMetaData) {
18771873
// Comment line, check for global/file @options and record them

src/harness/parallel/host.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ namespace Harness.Parallel.Host {
314314
stats.failures = errorResults.length;
315315
stats.tests = totalPassing + errorResults.length;
316316
stats.duration = duration;
317-
for (let j = 0; j < errorResults.length; j++) {
318-
const failure = errorResults[j];
317+
for (const failure of errorResults) {
319318
failures.push(makeMochaTest(failure));
320319
}
321320
if (noColors) {

src/harness/projectsRunner.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ class ProjectRunner extends RunnerBase {
140140

141141
// Clean up source map data that will be used in baselining
142142
if (sourceMapData) {
143-
for (let i = 0; i < sourceMapData.length; i++) {
144-
for (let j = 0; j < sourceMapData[i].sourceMapSources.length; j++) {
145-
sourceMapData[i].sourceMapSources[j] = cleanProjectUrl(sourceMapData[i].sourceMapSources[j]);
143+
for (const data of sourceMapData) {
144+
for (let j = 0; j < data.sourceMapSources.length; j++) {
145+
data.sourceMapSources[j] = cleanProjectUrl(data.sourceMapSources[j]);
146146
}
147-
sourceMapData[i].jsSourceMappingURL = cleanProjectUrl(sourceMapData[i].jsSourceMappingURL);
148-
sourceMapData[i].sourceMapSourceRoot = cleanProjectUrl(sourceMapData[i].sourceMapSourceRoot);
147+
data.jsSourceMappingURL = cleanProjectUrl(data.jsSourceMappingURL);
148+
data.sourceMapSourceRoot = cleanProjectUrl(data.sourceMapSourceRoot);
149149
}
150150
}
151151

src/harness/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ let iterations = 1;
2727

2828
function runTests(runners: RunnerBase[]) {
2929
for (let i = iterations; i > 0; i--) {
30-
for (let j = 0; j < runners.length; j++) {
31-
runners[j].initializeTests();
30+
for (const runner of runners) {
31+
runner.initializeTests();
3232
}
3333
}
3434
}

src/harness/rwcRunner.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,8 @@ class RWCRunner extends RunnerBase {
245245
*/
246246
public initializeTests(): void {
247247
// Read in and evaluate the test list
248-
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
249-
250-
for (let i = 0; i < testList.length; i++) {
251-
this.runTest(testList[i]);
248+
for (const test of this.tests && this.tests.length ? this.tests : this.enumerateTestFiles()) {
249+
this.runTest(test);
252250
}
253251
}
254252

0 commit comments

Comments
 (0)