Apply 'prefer-for-of' tslint rule (#19721)

This commit is contained in:
Andy 2017-11-03 15:20:35 -07:00 committed by GitHub
parent 8b5d8565cf
commit d998e97d8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 32 additions and 47 deletions

View File

@ -2854,8 +2854,7 @@ namespace ts {
function mapToTypeNodes(types: Type[], context: NodeBuilderContext): TypeNode[] {
if (some(types)) {
const result = [];
for (let i = 0; i < types.length; ++i) {
const type = types[i];
for (const type of types) {
const typeNode = typeToTypeNodeHelper(type, context);
if (typeNode) {
result.push(typeNode);

View File

@ -2661,8 +2661,8 @@ namespace ts {
function writeLines(text: string): void {
const lines = text.split(/\r\n?|\n/g);
const indentation = guessIndentation(lines);
for (let i = 0; i < lines.length; i++) {
const line = indentation ? lines[i].slice(indentation) : lines[i];
for (const lineText of lines) {
const line = indentation ? lineText.slice(indentation) : lineText;
if (line.length) {
writeLine();
write(line);

View File

@ -146,8 +146,7 @@ namespace ts {
function collectDependencyGroups(externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]) {
const groupIndices = createMap<number>();
const dependencyGroups: DependencyGroup[] = [];
for (let i = 0; i < externalImports.length; i++) {
const externalImport = externalImports[i];
for (const externalImport of externalImports) {
const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions);
if (externalModuleName) {
const text = externalModuleName.text;

View File

@ -305,9 +305,7 @@ namespace ts {
const optionsDescriptionMap = createMap<string[]>(); // Map between option.description and list of option.type if it is a kind
for (let i = 0; i < optsList.length; i++) {
const option = optsList[i];
for (const option of optsList) {
// If an option lacks a description,
// it is not officially supported.
if (!option.description) {

View File

@ -211,8 +211,8 @@ class CompilerBaselineRunner extends RunnerBase {
this.emit = false;
const opts = this.options.split(",");
for (let i = 0; i < opts.length; i++) {
switch (opts[i]) {
for (const opt of opts) {
switch (opt) {
case "emit":
this.emit = true;
break;

View File

@ -575,14 +575,13 @@ namespace Harness {
function filesInFolder(folder: string): string[] {
let paths: string[] = [];
const files = fs.readdirSync(folder);
for (let i = 0; i < files.length; i++) {
const pathToFile = pathModule.join(folder, files[i]);
for (const file of fs.readdirSync(folder)) {
const pathToFile = pathModule.join(folder, file);
const stat = fs.statSync(pathToFile);
if (options.recursive && stat.isDirectory()) {
paths = paths.concat(filesInFolder(pathToFile));
}
else if (stat.isFile() && (!spec || files[i].match(spec))) {
else if (stat.isFile() && (!spec || file.match(spec))) {
paths.push(pathToFile);
}
}
@ -1581,10 +1580,8 @@ namespace Harness {
// Preserve legacy behavior
if (lastIndexWritten === undefined) {
for (let i = 0; i < codeLines.length; i++) {
const currentCodeLine = codeLines[i];
typeLines += currentCodeLine + "\r\n";
typeLines += "No type information for this code.";
for (const codeLine of codeLines) {
typeLines += codeLine + "\r\nNo type information for this code.";
}
}
else {
@ -1870,8 +1867,7 @@ namespace Harness {
let currentFileName: any = undefined;
let refs: string[] = [];
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
for (const line of lines) {
const testMetaData = optionRegex.exec(line);
if (testMetaData) {
// Comment line, check for global/file @options and record them

View File

@ -314,8 +314,7 @@ namespace Harness.Parallel.Host {
stats.failures = errorResults.length;
stats.tests = totalPassing + errorResults.length;
stats.duration = duration;
for (let j = 0; j < errorResults.length; j++) {
const failure = errorResults[j];
for (const failure of errorResults) {
failures.push(makeMochaTest(failure));
}
if (noColors) {

View File

@ -140,12 +140,12 @@ class ProjectRunner extends RunnerBase {
// Clean up source map data that will be used in baselining
if (sourceMapData) {
for (let i = 0; i < sourceMapData.length; i++) {
for (let j = 0; j < sourceMapData[i].sourceMapSources.length; j++) {
sourceMapData[i].sourceMapSources[j] = cleanProjectUrl(sourceMapData[i].sourceMapSources[j]);
for (const data of sourceMapData) {
for (let j = 0; j < data.sourceMapSources.length; j++) {
data.sourceMapSources[j] = cleanProjectUrl(data.sourceMapSources[j]);
}
sourceMapData[i].jsSourceMappingURL = cleanProjectUrl(sourceMapData[i].jsSourceMappingURL);
sourceMapData[i].sourceMapSourceRoot = cleanProjectUrl(sourceMapData[i].sourceMapSourceRoot);
data.jsSourceMappingURL = cleanProjectUrl(data.jsSourceMappingURL);
data.sourceMapSourceRoot = cleanProjectUrl(data.sourceMapSourceRoot);
}
}

View File

@ -27,8 +27,8 @@ let iterations = 1;
function runTests(runners: RunnerBase[]) {
for (let i = iterations; i > 0; i--) {
for (let j = 0; j < runners.length; j++) {
runners[j].initializeTests();
for (const runner of runners) {
runner.initializeTests();
}
}
}

View File

@ -245,10 +245,8 @@ class RWCRunner extends RunnerBase {
*/
public initializeTests(): void {
// Read in and evaluate the test list
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
for (let i = 0; i < testList.length; i++) {
this.runTest(testList[i]);
for (const test of this.tests && this.tests.length ? this.tests : this.enumerateTestFiles()) {
this.runTest(test);
}
}

View File

@ -386,9 +386,9 @@ namespace Harness.SourceMapRecorder {
if (currentSpan.decodeErrors) {
// If there are decode errors, write
for (let i = 0; i < currentSpan.decodeErrors.length; i++) {
for (const decodeError of currentSpan.decodeErrors) {
writeSourceMapIndent(prevEmittedCol, markerIds[index]);
sourceMapRecorder.WriteLine(currentSpan.decodeErrors[i]);
sourceMapRecorder.WriteLine(decodeError);
}
}
@ -442,8 +442,7 @@ namespace Harness.SourceMapRecorder {
let prevSourceFile: ts.SourceFile;
SourceMapSpanWriter.initializeSourceMapSpanWriter(sourceMapRecorder, sourceMapData, jsFiles[i]);
for (let j = 0; j < sourceMapData.sourceMapDecodedMappings.length; j++) {
const decodedSourceMapping = sourceMapData.sourceMapDecodedMappings[j];
for (const decodedSourceMapping of sourceMapData.sourceMapDecodedMappings) {
const currentSourceFile = program.getSourceFile(sourceMapData.inputSourceFileNames[decodedSourceMapping.sourceIndex]);
if (currentSourceFile !== prevSourceFile) {
SourceMapSpanWriter.recordNewSourceFileSpan(decodedSourceMapping, currentSourceFile.text);

View File

@ -18,8 +18,8 @@ class UserCodeRunner extends RunnerBase {
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
describe(`${this.kind()} code samples`, () => {
for (let i = 0; i < testList.length; i++) {
this.runTest(testList[i]);
for (const test of testList) {
this.runTest(test);
}
});
}

View File

@ -20,8 +20,8 @@ namespace ts.codefix {
// i.e. super(this.a), since in that case we won't suggest a fix
if (superCall.expression && superCall.expression.kind === SyntaxKind.CallExpression) {
const expressionArguments = (<CallExpression>superCall.expression).arguments;
for (let i = 0; i < expressionArguments.length; i++) {
if ((<PropertyAccessExpression>expressionArguments[i]).expression === token) {
for (const arg of expressionArguments) {
if ((<PropertyAccessExpression>arg).expression === token) {
return undefined;
}
}

View File

@ -104,8 +104,7 @@ namespace ts.codefix {
}
const signatureDeclarations: MethodDeclaration[] = [];
for (let i = 0; i < signatures.length; i++) {
const signature = signatures[i];
for (const signature of signatures) {
const methodDeclaration = signatureToMethodDeclaration(signature, enclosingDeclaration);
if (methodDeclaration) {
signatureDeclarations.push(methodDeclaration);
@ -194,8 +193,7 @@ namespace ts.codefix {
let maxArgsSignature = signatures[0];
let minArgumentCount = signatures[0].minArgumentCount;
let someSigHasRestParameter = false;
for (let i = 0; i < signatures.length; i++) {
const sig = signatures[i];
for (const sig of signatures) {
minArgumentCount = Math.min(sig.minArgumentCount, minArgumentCount);
if (sig.hasRestParameter) {
someSigHasRestParameter = true;

View File

@ -98,7 +98,6 @@
"object-literal-key-quotes": false,
"ordered-imports": false,
"prefer-conditional-expression": false,
"prefer-for-of": false,
"radix": false,
"space-before-function-paren": false,
"trailing-comma": false,