Skip to content

Commit 44da834

Browse files
authored
Add fix option to lint task (#24344)
1 parent 7e4b20e commit 44da834

File tree

2 files changed

+10
-56
lines changed

2 files changed

+10
-56
lines changed

Gulpfile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const constEnumCaptureRegexp = /^(\s*)(export )?const enum (\S+) {(\s*)$/gm;
3636
const constEnumReplacement = "$1$2enum $3 {$4";
3737

3838
const cmdLineOptions = minimist(process.argv.slice(2), {
39-
boolean: ["debug", "inspect", "light", "colors", "lint", "soft"],
39+
boolean: ["debug", "inspect", "light", "colors", "lint", "soft", "fix"],
4040
string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"],
4141
alias: {
4242
"b": "browser",
@@ -47,6 +47,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
4747
"r": "reporter",
4848
"c": "colors", "color": "colors",
4949
"w": "workers",
50+
"f": "fix",
5051
},
5152
default: {
5253
soft: false,
@@ -61,6 +62,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
6162
light: process.env.light === undefined || process.env.light !== "false",
6263
reporter: process.env.reporter || process.env.r,
6364
lint: process.env.lint || true,
65+
fix: process.env.fix || process.env.f,
6466
workers: process.env.workerCount || os.cpus().length,
6567
}
6668
});
@@ -1070,7 +1072,7 @@ gulp.task("build-rules", "Compiles tslint rules to js", () => {
10701072
gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => {
10711073
if (fold.isTravis()) console.log(fold.start("lint"));
10721074
for (const project of ["scripts/tslint/tsconfig.json", "src/tsconfig-base.json"]) {
1073-
const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
1075+
const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish${cmdLineOptions.fix ? " --fix" : ""}`;
10741076
console.log("Linting: " + cmd);
10751077
child_process.execSync(cmd, { stdio: [0, 1, 2] });
10761078
}

Jakefile.js

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,65 +1114,17 @@ task("build-rules-end", [], function () {
11141114
if (fold.isTravis()) console.log(fold.end("build-rules"));
11151115
});
11161116

1117-
var lintTargets = compilerSources
1118-
.concat(harnessSources)
1119-
// Other harness sources
1120-
.concat(["instrumenter.ts"].map(function (f) { return path.join(harnessDirectory, f); }))
1121-
.concat(serverSources)
1122-
.concat(tslintRulesFiles)
1123-
.concat(servicesSources)
1124-
.concat(typingsInstallerSources)
1125-
.concat(cancellationTokenSources)
1126-
.concat(["Gulpfile.ts"])
1127-
.concat([nodeServerInFile, perftscPath, "tests/perfsys.ts", webhostPath])
1128-
.map(function (p) { return path.resolve(p); });
1129-
// keep only unique items
1130-
lintTargets = Array.from(new Set(lintTargets));
1131-
1132-
function sendNextFile(files, child, callback, failures) {
1133-
var file = files.pop();
1134-
if (file) {
1135-
console.log("Linting '" + file + "'.");
1136-
child.send({ kind: "file", name: file });
1137-
}
1138-
else {
1139-
child.send({ kind: "close" });
1140-
callback(failures);
1141-
}
1142-
}
1143-
1144-
function spawnLintWorker(files, callback) {
1145-
var child = child_process.fork("./scripts/parallel-lint");
1146-
var failures = 0;
1147-
child.on("message", function (data) {
1148-
switch (data.kind) {
1149-
case "result":
1150-
if (data.failures > 0) {
1151-
failures += data.failures;
1152-
console.log(data.output);
1153-
}
1154-
sendNextFile(files, child, callback, failures);
1155-
break;
1156-
case "error":
1157-
console.error(data.error);
1158-
failures++;
1159-
sendNextFile(files, child, callback, failures);
1160-
break;
1161-
}
1162-
});
1163-
sendNextFile(files, child, callback, failures);
1164-
}
1165-
11661117
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
11671118
task("lint", ["build-rules"], () => {
11681119
if (fold.isTravis()) console.log(fold.start("lint"));
1169-
function lint(project, cb) {
1170-
const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
1120+
function lint(project, cb) {
1121+
const fix = process.env.fix || process.env.f;
1122+
const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish${fix ? " --fix" : ""}`;
11711123
console.log("Linting: " + cmd);
11721124
jake.exec([cmd], cb, /** @type {jake.ExecOptions} */({ interactive: true, windowsVerbatimArguments: true }));
1173-
}
1174-
lint("scripts/tslint/tsconfig.json", () => lint("src/tsconfig-base.json", () => {
1125+
}
1126+
lint("scripts/tslint/tsconfig.json", () => lint("src/tsconfig-base.json", () => {
11751127
if (fold.isTravis()) console.log(fold.end("lint"));
11761128
complete();
1177-
}));
1129+
}));
11781130
});

0 commit comments

Comments
 (0)