Skip to content

Commit 0152e8c

Browse files
author
Andy Hanson
committed
Fix lint scripts
1 parent 2305c10 commit 0152e8c

File tree

6 files changed

+109
-73
lines changed

6 files changed

+109
-73
lines changed

Gulpfile.ts

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as cp from "child_process";
33
import * as path from "path";
44
import * as fs from "fs";
5+
import child_process = require("child_process");
56
import originalGulp = require("gulp");
67
import helpMaker = require("gulp-help");
78
import runSequence = require("run-sequence");
@@ -1019,40 +1020,16 @@ function spawnLintWorker(files: {path: string}[], callback: (failures: number) =
10191020
}
10201021

10211022
gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => {
1022-
const fileMatcher = RegExp(cmdLineOptions["files"]);
10231023
if (fold.isTravis()) console.log(fold.start("lint"));
1024-
1025-
let files: {stat: fs.Stats, path: string}[] = [];
1026-
return gulp.src(lintTargets, { read: false })
1027-
.pipe(through2.obj((chunk, enc, cb) => {
1028-
files.push(chunk);
1029-
cb();
1030-
}, (cb) => {
1031-
files = files.filter(file => fileMatcher.test(file.path)).sort((filea, fileb) => filea.stat.size - fileb.stat.size);
1032-
const workerCount = cmdLineOptions["workers"];
1033-
for (let i = 0; i < workerCount; i++) {
1034-
spawnLintWorker(files, finished);
1035-
}
1036-
1037-
let completed = 0;
1038-
let failures = 0;
1039-
function finished(fails) {
1040-
completed++;
1041-
failures += fails;
1042-
if (completed === workerCount) {
1043-
if (fold.isTravis()) console.log(fold.end("lint"));
1044-
if (failures > 0) {
1045-
throw new Error(`Linter errors: ${failures}`);
1046-
}
1047-
else {
1048-
cb();
1049-
}
1050-
}
1051-
}
1052-
}));
1024+
const fileMatcher = cmdLineOptions["files"];
1025+
const files = fileMatcher
1026+
? `src/**/${fileMatcher}`
1027+
: "Gulpfile.ts 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts' --exclude 'src/harness/unittests/services/**/*.ts'";
1028+
const cmd = `node node_modules/tslint/bin/tslint ${files} --format stylish`;
1029+
console.log("Linting: " + cmd);
1030+
child_process.execSync(cmd, { stdio: [0, 1, 2] });
10531031
});
10541032

1055-
10561033
gulp.task("default", "Runs 'local'", ["local"]);
10571034

10581035
gulp.task("watch", "Watches the src/ directory for changes and executes runtests-parallel.", [], () => {

Jakefile.js

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,43 +1177,16 @@ function spawnLintWorker(files, callback) {
11771177
}
11781178

11791179
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
1180-
task("lint", ["build-rules"], function () {
1180+
task("lint", ["build-rules"], () => {
11811181
if (fold.isTravis()) console.log(fold.start("lint"));
1182-
var startTime = mark();
1183-
var failed = 0;
1184-
var fileMatcher = RegExp(process.env.f || process.env.file || process.env.files || "");
1185-
var done = {};
1186-
for (var i in lintTargets) {
1187-
var target = lintTargets[i];
1188-
if (!done[target] && fileMatcher.test(target)) {
1189-
done[target] = fs.statSync(target).size;
1190-
}
1191-
}
1192-
1193-
var workerCount = (process.env.workerCount && +process.env.workerCount) || os.cpus().length;
1194-
1195-
var names = Object.keys(done).sort(function (namea, nameb) {
1196-
return done[namea] - done[nameb];
1182+
const fileMatcher = process.env.f || process.env.file || process.env.files;
1183+
const files = fileMatcher
1184+
? `src/**/${fileMatcher}`
1185+
: "Gulpfile.ts 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts' --exclude 'src/harness/unittests/services/**/*.ts'";
1186+
const cmd = `node node_modules/tslint/bin/tslint ${files} --format stylish`;
1187+
console.log("Linting: " + cmd);
1188+
jake.exec([cmd], { interactive: true }, () => {
1189+
if (fold.isTravis()) console.log(fold.end("lint"));
1190+
complete();
11971191
});
1198-
1199-
for (var i = 0; i < workerCount; i++) {
1200-
spawnLintWorker(names, finished);
1201-
}
1202-
1203-
var completed = 0;
1204-
var failures = 0;
1205-
function finished(fails) {
1206-
completed++;
1207-
failures += fails;
1208-
if (completed === workerCount) {
1209-
measure(startTime);
1210-
if (fold.isTravis()) console.log(fold.end("lint"));
1211-
if (failures > 0) {
1212-
fail('Linter errors.', failed);
1213-
}
1214-
else {
1215-
complete();
1216-
}
1217-
}
1218-
}
1219-
}, { async: true });
1192+
});

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ namespace FourSlash {
931931
const { isWriteAccess, isDefinition, isInString } = (r.marker && r.marker.data) || { isWriteAccess: false, isDefinition: false, isInString: undefined };
932932
const result: ts.ReferenceEntry = { fileName: r.fileName, textSpan: { start: r.start, length: r.end - r.start }, isWriteAccess: !!isWriteAccess, isDefinition: !!isDefinition };
933933
if (isInString !== undefined) {
934-
result.isInString = isInString
934+
result.isInString = isInString;
935935
}
936936
return result;
937937
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
///<reference path='_project.ts'/>
2+
3+
describe('getFormattingEditsForRange', function() {
4+
//
5+
// Verify that formatting the typescript file "sourceFileName" results in the
6+
// baseline file "baselineFileName".
7+
//
8+
function getFormattingEditsForRange(sourceFileName: string) {
9+
var baselineFileName = "tests/cases/unittests/services/testCode/formatting/" + sourceFileName + "BaseLine.ts";
10+
sourceFileName = "tests/cases/unittests/services/testCode/formatting/" + sourceFileName + ".ts";
11+
12+
var typescriptLS = new Harness.TypeScriptLS();
13+
typescriptLS.addDefaultLibrary();
14+
typescriptLS.addFile(sourceFileName);
15+
16+
var ls = typescriptLS.getLanguageService();
17+
var script = ls.languageService.getScriptAST(sourceFileName);
18+
assert.notNull(script);
19+
20+
var edits = ls.languageService.getFormattingEditsForRange(sourceFileName, 0, script.limChar, new Services.FormatCodeOptions());
21+
typescriptLS.checkEdits(sourceFileName, baselineFileName, edits);
22+
}
23+
24+
describe('test cases for formatting engine', function() {
25+
it("formats typescript constructs properly", function() {
26+
getFormattingEditsForRange('typescriptConstructs');
27+
});
28+
it("formats document ready function properly", function() {
29+
getFormattingEditsForRange('documentReadyFunction');
30+
});
31+
it("formats on closing bracket properly", function() {
32+
getFormattingEditsForRange('onClosingBracket');
33+
});
34+
it("formats various javascript constructs", function() {
35+
getFormattingEditsForRange('various');
36+
});
37+
it("formats main javascript program", function() {
38+
getFormattingEditsForRange('main');
39+
});
40+
it("formats on semicolon properly", function() {
41+
getFormattingEditsForRange('onSemiColon');
42+
});
43+
it("formats enum with trailling tab characters properly", function() {
44+
getFormattingEditsForRange('tabAfterCloseCurly');
45+
});
46+
it("formats object literal", function() {
47+
getFormattingEditsForRange('objectLiteral');
48+
});
49+
it("formats with statements", function() {
50+
getFormattingEditsForRange('withStatement');
51+
});
52+
it("formats ':' and '?' in parameters", function() {
53+
getFormattingEditsForRange('colonAndQMark');
54+
});
55+
it("formats 'import' declaration", function() {
56+
getFormattingEditsForRange('importDeclaration');
57+
});
58+
it("formats exported class with implicit module", function() {
59+
//TODO: this is to force generation of implicit module in AST
60+
var svGenTarget = TypeScript.moduleGenTarget;
61+
try {
62+
TypeScript.moduleGenTarget = TypeScript.ModuleGenTarget.Asynchronous;
63+
getFormattingEditsForRange('implicitModule');
64+
}
65+
finally {
66+
TypeScript.moduleGenTarget = svGenTarget;
67+
}
68+
});
69+
it("formats constructor statements correctelly", function() {
70+
getFormattingEditsForRange('spaceAfterConstructor');
71+
});
72+
it("formats classes and interfaces correctelly", function() {
73+
getFormattingEditsForRange('classes');
74+
});
75+
it("formats modules correctly", function() {
76+
getFormattingEditsForRange('modules');
77+
});
78+
it("formats fat arrow expressions correctelly", function() {
79+
getFormattingEditsForRange('fatArrowFunctions');
80+
});
81+
it("formats empty object/interface literals correctelly", function() {
82+
getFormattingEditsForRange('emptyInterfaceLiteral');
83+
});
84+
it("formats variable declaration lists", function() {
85+
getFormattingEditsForRange('formatVariableDeclarationList');
86+
});
87+
});
88+
});

src/lib/es5.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/// ECMAScript APIs
33
/////////////////////////////
44

5-
// tslint:disable no-var-keyword
6-
75
declare const NaN: number;
86
declare const Infinity: number;
97

tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
lib.d.ts(34,18): error TS2300: Duplicate identifier 'eval'.
1+
lib.d.ts(32,18): error TS2300: Duplicate identifier 'eval'.
22
tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS1100: Invalid use of 'eval' in strict mode.
33
tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS2300: Duplicate identifier 'eval'.
44

0 commit comments

Comments
 (0)