Skip to content

Commit d5c1b71

Browse files
author
Andy
authored
Merge pull request #14710 from Microsoft/lint
Fix lint errors
2 parents 082cf11 + 0152e8c commit d5c1b71

27 files changed

+155
-206
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/compiler/moduleNameResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="core.ts" />
1+
/// <reference path="core.ts" />
22
/// <reference path="diagnosticInformationMap.generated.ts" />
33

44
namespace ts {

src/compiler/program.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ namespace ts {
298298
let noDiagnosticsTypeChecker: TypeChecker;
299299
let classifiableNames: Map<string>;
300300

301-
let cachedSemanticDiagnosticsForFile: DiagnosticCache = {};
302-
let cachedDeclarationDiagnosticsForFile: DiagnosticCache = {};
301+
const cachedSemanticDiagnosticsForFile: DiagnosticCache = {};
302+
const cachedDeclarationDiagnosticsForFile: DiagnosticCache = {};
303303

304304
let resolvedTypeReferenceDirectives = createMap<ResolvedTypeReferenceDirective>();
305305
let fileProcessingDiagnostics = createDiagnosticCollection();
@@ -1105,7 +1105,7 @@ namespace ts {
11051105
return getAndCacheDiagnostics(sourceFile, cancellationToken, cachedDeclarationDiagnosticsForFile, getDeclarationDiagnosticsForFileNoCache);
11061106
}
11071107

1108-
function getDeclarationDiagnosticsForFileNoCache(sourceFile: SourceFile| undefined, cancellationToken: CancellationToken) {
1108+
function getDeclarationDiagnosticsForFileNoCache(sourceFile: SourceFile | undefined, cancellationToken: CancellationToken) {
11091109
return runWithCancellationToken(() => {
11101110
const resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
11111111
// Don't actually write any files since we're just getting diagnostics.

src/harness/fourslash.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,9 @@ namespace FourSlash {
927927
this.assertObjectsEqual<ReferencesJson>(fullActual, fullExpected);
928928
}
929929

930-
function rangeToReferenceEntry(r: Range) {
931-
let { isWriteAccess, isDefinition, isInString } = (r.marker && r.marker.data) || { isWriteAccess: false, isDefinition: false, isInString: undefined };
932-
isWriteAccess = !!isWriteAccess; isDefinition = !!isDefinition;
933-
const result: any = { fileName: r.fileName, textSpan: { start: r.start, length: r.end - r.start }, isWriteAccess, isDefinition };
930+
function rangeToReferenceEntry(r: Range): ts.ReferenceEntry {
931+
const { isWriteAccess, isDefinition, isInString } = (r.marker && r.marker.data) || { isWriteAccess: false, isDefinition: false, isInString: undefined };
932+
const result: ts.ReferenceEntry = { fileName: r.fileName, textSpan: { start: r.start, length: r.end - r.start }, isWriteAccess: !!isWriteAccess, isDefinition: !!isDefinition };
934933
if (isInString !== undefined) {
935934
result.isInString = isInString;
936935
}
@@ -2291,7 +2290,6 @@ namespace FourSlash {
22912290
else {
22922291
if (actual === undefined) {
22932292
this.raiseError(`${name} failed - expected the template {newText: "${expected.newText}", caretOffset: "${expected.caretOffset}"} but got nothing instead`);
2294-
22952293
}
22962294

22972295
if (actual.newText !== expected.newText) {

src/harness/unittests/services/formatting/getFormattingEditsForRange.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
///<reference path='_project.ts'/>
1+
///<reference path='_project.ts'/>
22

33
describe('getFormattingEditsForRange', function() {
44
//

src/harness/unittests/textChanges.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/// <reference path="..\..\services\textChanges.ts" />
33
/// <reference path="..\harness.ts" />
44

5+
// Some tests have trailing whitespace
6+
// tslint:disable trim-trailing-whitespace
7+
58
namespace ts {
69
describe("textChanges", () => {
710
function findChild(name: string, n: Node) {
@@ -572,7 +575,7 @@ import {
572575
} from "bar"`;
573576
runSingleFileTest("insertNodeInListAfter10", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
574577
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(createIdentifier("b"), createIdentifier("a")));
575-
})
578+
});
576579
}
577580
{
578581
const text = `
@@ -581,7 +584,7 @@ import {
581584
} from "bar"`;
582585
runSingleFileTest("insertNodeInListAfter11", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
583586
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(createIdentifier("b"), createIdentifier("a")));
584-
})
587+
});
585588
}
586589
{
587590
const text = `
@@ -590,7 +593,7 @@ import {
590593
} from "bar"`;
591594
runSingleFileTest("insertNodeInListAfter12", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
592595
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));
593-
})
596+
});
594597
}
595598
{
596599
const text = `
@@ -599,7 +602,7 @@ import {
599602
} from "bar"`;
600603
runSingleFileTest("insertNodeInListAfter13", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
601604
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));
602-
})
605+
});
603606
}
604607
{
605608
const text = `
@@ -609,7 +612,7 @@ import {
609612
} from "bar"`;
610613
runSingleFileTest("insertNodeInListAfter14", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
611614
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(createIdentifier("b"), createIdentifier("a")));
612-
})
615+
});
613616
}
614617
{
615618
const text = `
@@ -619,7 +622,7 @@ import {
619622
} from "bar"`;
620623
runSingleFileTest("insertNodeInListAfter15", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
621624
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(createIdentifier("b"), createIdentifier("a")));
622-
})
625+
});
623626
}
624627
{
625628
const text = `
@@ -629,7 +632,7 @@ import {
629632
} from "bar"`;
630633
runSingleFileTest("insertNodeInListAfter16", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
631634
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));
632-
})
635+
});
633636
}
634637
{
635638
const text = `
@@ -639,7 +642,7 @@ import {
639642
} from "bar"`;
640643
runSingleFileTest("insertNodeInListAfter17", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
641644
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));
642-
})
645+
});
643646
}
644647
{
645648
const text = `
@@ -648,15 +651,15 @@ import {
648651
} from "bar"`;
649652
runSingleFileTest("insertNodeInListAfter18", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
650653
changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));
651-
})
654+
});
652655
}
653656
{
654657
const text = `
655658
class A {
656659
x;
657660
}`;
658661
runSingleFileTest("insertNodeAfterMultipleNodes", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
659-
let newNodes = [];
662+
const newNodes = [];
660663
for (let i = 0; i < 11 /*error doesn't occur with fewer nodes*/; ++i) {
661664
newNodes.push(
662665
createProperty(undefined, undefined, i + "", undefined, undefined, undefined));
@@ -714,7 +717,7 @@ class A {
714717
class A {
715718
x = foo
716719
}
717-
`
720+
`;
718721
runSingleFileTest("insertNodeInClassAfterNodeWithoutSeparator1", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
719722
const newNode = createProperty(
720723
/*decorators*/ undefined,
@@ -732,7 +735,7 @@ class A {
732735
x() {
733736
}
734737
}
735-
`
738+
`;
736739
runSingleFileTest("insertNodeInClassAfterNodeWithoutSeparator2", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
737740
const newNode = createProperty(
738741
/*decorators*/ undefined,
@@ -749,7 +752,7 @@ class A {
749752
interface A {
750753
x
751754
}
752-
`
755+
`;
753756
runSingleFileTest("insertNodeInInterfaceAfterNodeWithoutSeparator1", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
754757
const newNode = createProperty(
755758
/*decorators*/ undefined,
@@ -766,7 +769,7 @@ interface A {
766769
interface A {
767770
x()
768771
}
769-
`
772+
`;
770773
runSingleFileTest("insertNodeInInterfaceAfterNodeWithoutSeparator2", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
771774
const newNode = createProperty(
772775
/*decorators*/ undefined,
@@ -781,7 +784,7 @@ interface A {
781784
{
782785
const text = `
783786
let x = foo
784-
`
787+
`;
785788
runSingleFileTest("insertNodeInStatementListAfterNodeWithoutSeparator1", noop, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {
786789
const newNode = createStatement(createParen(createLiteral(1)));
787790
changeTracker.insertNodeAfter(sourceFile, findVariableStatementContaining("x", sourceFile), newNode, { suffix: newLineCharacter });

src/lib/dom.iterable.d.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ interface DOMTokenList {
55
}
66

77
interface NodeList {
8-
9-
10-
/**
8+
/**
119
* Returns an array of key, value pairs for every entry in the list
1210
*/
1311
entries(): IterableIterator<[number, Node]>;
@@ -17,23 +15,23 @@ interface NodeList {
1715
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
1816
*/
1917
forEach(callbackfn: (value: Node, index: number, listObj: NodeList) => void, thisArg?: any): void;
20-
/**
18+
/**
2119
* Returns an list of keys in the list
2220
*/
2321
keys(): IterableIterator<number>;
2422

25-
/**
23+
/**
2624
* Returns an list of values in the list
2725
*/
2826
values(): IterableIterator<Node>;
29-
3027

31-
[Symbol.iterator](): IterableIterator<Node>
28+
29+
[Symbol.iterator](): IterableIterator<Node>;
3230
}
3331

3432
interface NodeListOf<TNode extends Node> {
3533

36-
/**
34+
/**
3735
* Returns an array of key, value pairs for every entry in the list
3836
*/
3937
entries(): IterableIterator<[number, TNode]>;
@@ -44,14 +42,14 @@ interface NodeListOf<TNode extends Node> {
4442
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
4543
*/
4644
forEach(callbackfn: (value: TNode, index: number, listObj: NodeListOf<TNode>) => void, thisArg?: any): void;
47-
/**
45+
/**
4846
* Returns an list of keys in the list
4947
*/
5048
keys(): IterableIterator<number>;
51-
/**
49+
/**
5250
* Returns an list of values in the list
5351
*/
54-
values(): IterableIterator<TNode>;
55-
56-
[Symbol.iterator](): IterableIterator<TNode>
52+
values(): IterableIterator<TNode>;
53+
54+
[Symbol.iterator](): IterableIterator<TNode>;
5755
}

src/lib/es2015.collection.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare var Map: MapConstructor;
1717

1818
interface ReadonlyMap<K, V> {
1919
forEach(callbackfn: (value: V, key: K, map: ReadonlyMap<K, V>) => void, thisArg?: any): void;
20-
get(key: K): V|undefined;
20+
get(key: K): V | undefined;
2121
has(key: K): boolean;
2222
readonly size: number;
2323
}

0 commit comments

Comments
 (0)