From 44da8345514a00c393dff711eff5158ecd6705a8 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 22 May 2018 17:01:45 -0700 Subject: [PATCH] Add fix option to lint task (#24344) --- Gulpfile.js | 6 ++++-- Jakefile.js | 60 ++++++----------------------------------------------- 2 files changed, 10 insertions(+), 56 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index af7461ba7e6..5b5992496c4 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -36,7 +36,7 @@ const constEnumCaptureRegexp = /^(\s*)(export )?const enum (\S+) {(\s*)$/gm; const constEnumReplacement = "$1$2enum $3 {$4"; const cmdLineOptions = minimist(process.argv.slice(2), { - boolean: ["debug", "inspect", "light", "colors", "lint", "soft"], + boolean: ["debug", "inspect", "light", "colors", "lint", "soft", "fix"], string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"], alias: { "b": "browser", @@ -47,6 +47,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), { "r": "reporter", "c": "colors", "color": "colors", "w": "workers", + "f": "fix", }, default: { soft: false, @@ -61,6 +62,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), { light: process.env.light === undefined || process.env.light !== "false", reporter: process.env.reporter || process.env.r, lint: process.env.lint || true, + fix: process.env.fix || process.env.f, workers: process.env.workerCount || os.cpus().length, } }); @@ -1070,7 +1072,7 @@ gulp.task("build-rules", "Compiles tslint rules to js", () => { gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => { if (fold.isTravis()) console.log(fold.start("lint")); for (const project of ["scripts/tslint/tsconfig.json", "src/tsconfig-base.json"]) { - const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`; + const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish${cmdLineOptions.fix ? " --fix" : ""}`; console.log("Linting: " + cmd); child_process.execSync(cmd, { stdio: [0, 1, 2] }); } diff --git a/Jakefile.js b/Jakefile.js index 2e18fe1fa71..55729eecaad 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -1114,65 +1114,17 @@ task("build-rules-end", [], function () { if (fold.isTravis()) console.log(fold.end("build-rules")); }); -var lintTargets = compilerSources - .concat(harnessSources) - // Other harness sources - .concat(["instrumenter.ts"].map(function (f) { return path.join(harnessDirectory, f); })) - .concat(serverSources) - .concat(tslintRulesFiles) - .concat(servicesSources) - .concat(typingsInstallerSources) - .concat(cancellationTokenSources) - .concat(["Gulpfile.ts"]) - .concat([nodeServerInFile, perftscPath, "tests/perfsys.ts", webhostPath]) - .map(function (p) { return path.resolve(p); }); -// keep only unique items -lintTargets = Array.from(new Set(lintTargets)); - -function sendNextFile(files, child, callback, failures) { - var file = files.pop(); - if (file) { - console.log("Linting '" + file + "'."); - child.send({ kind: "file", name: file }); - } - else { - child.send({ kind: "close" }); - callback(failures); - } -} - -function spawnLintWorker(files, callback) { - var child = child_process.fork("./scripts/parallel-lint"); - var failures = 0; - child.on("message", function (data) { - switch (data.kind) { - case "result": - if (data.failures > 0) { - failures += data.failures; - console.log(data.output); - } - sendNextFile(files, child, callback, failures); - break; - case "error": - console.error(data.error); - failures++; - sendNextFile(files, child, callback, failures); - break; - } - }); - sendNextFile(files, child, callback, failures); -} - desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex"); task("lint", ["build-rules"], () => { if (fold.isTravis()) console.log(fold.start("lint")); - function lint(project, cb) { - const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`; + function lint(project, cb) { + const fix = process.env.fix || process.env.f; + const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish${fix ? " --fix" : ""}`; console.log("Linting: " + cmd); jake.exec([cmd], cb, /** @type {jake.ExecOptions} */({ interactive: true, windowsVerbatimArguments: true })); - } - lint("scripts/tslint/tsconfig.json", () => lint("src/tsconfig-base.json", () => { + } + lint("scripts/tslint/tsconfig.json", () => lint("src/tsconfig-base.json", () => { if (fold.isTravis()) console.log(fold.end("lint")); complete(); - })); + })); });