Skip to content

Commit 7347e5e

Browse files
author
Andy Hanson
committed
Merge branch 'master' into lint-linter
2 parents e73fffd + 1798e8f commit 7347e5e

37 files changed

+425
-169
lines changed

Gulpfile.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function prependCopyright(outputCopyright: boolean = !useDebugMode) {
384384
}
385385

386386
gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
387-
const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
387+
const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
388388
return localCompilerProject.src()
389389
.pipe(newer(builtLocalCompiler))
390390
.pipe(sourcemaps.init())
@@ -395,14 +395,14 @@ gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
395395
});
396396

397397
gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
398-
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false));
398+
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/ false));
399399
const {js, dts} = servicesProject.src()
400400
.pipe(newer(servicesFile))
401401
.pipe(sourcemaps.init())
402402
.pipe(servicesProject());
403403
const completedJs = js.pipe(prependCopyright())
404404
.pipe(sourcemaps.write("."));
405-
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true))
405+
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/ true))
406406
.pipe(insert.transform((contents, file) => {
407407
file.path = standaloneDefinitionsFile;
408408
return contents.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4");
@@ -429,7 +429,7 @@ gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
429429
// cancellationToken.js
430430
const cancellationTokenJs = path.join(builtLocalDirectory, "cancellationToken.js");
431431
gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => {
432-
const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
432+
const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
433433
return cancellationTokenProject.src()
434434
.pipe(newer(cancellationTokenJs))
435435
.pipe(sourcemaps.init())
@@ -442,7 +442,7 @@ gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => {
442442
// typingsInstallerFile.js
443443
const typingsInstallerJs = path.join(builtLocalDirectory, "typingsInstaller.js");
444444
gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => {
445-
const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
445+
const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
446446
return cancellationTokenProject.src()
447447
.pipe(newer(typingsInstallerJs))
448448
.pipe(sourcemaps.init())
@@ -455,7 +455,7 @@ gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => {
455455
const serverFile = path.join(builtLocalDirectory, "tsserver.js");
456456

457457
gulp.task(serverFile, /*help*/ false, [servicesFile, typingsInstallerJs, cancellationTokenJs], () => {
458-
const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
458+
const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
459459
return serverProject.src()
460460
.pipe(newer(serverFile))
461461
.pipe(sourcemaps.init())
@@ -479,7 +479,7 @@ gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile], (done) => {
479479
js.pipe(prependCopyright())
480480
.pipe(sourcemaps.write("."))
481481
.pipe(gulp.dest("src/server")),
482-
dts.pipe(prependCopyright(/*outputCopyright*/true))
482+
dts.pipe(prependCopyright(/*outputCopyright*/ true))
483483
.pipe(insert.transform((content) => {
484484
return content + "\r\nexport = ts;\r\nexport as namespace ts;";
485485
}))
@@ -551,7 +551,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
551551
// Task to build the tests infrastructure using the built compiler
552552
const run = path.join(builtLocalDirectory, "run.js");
553553
gulp.task(run, /*help*/ false, [servicesFile], () => {
554-
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
554+
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
555555
return testProject.src()
556556
.pipe(newer(run))
557557
.pipe(sourcemaps.init())
@@ -757,7 +757,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
757757
browserify(intoStream(file.contents), { debug: true })
758758
.bundle((err, res) => {
759759
// assumes file.contents is a Buffer
760-
const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/true).toJSON());
760+
const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/ true).toJSON());
761761
delete maps.sourceRoot;
762762
maps.sources = maps.sources.map(s => path.resolve(s === "_stream_0.js" ? "built/local/_stream_0.js" : s));
763763
// Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
@@ -775,7 +775,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
775775
});
776776
const finalMap = chain.apply();
777777
file.sourceMap = finalMap;
778-
next(undefined, file);
778+
next(/*err*/ undefined, file);
779779
});
780780
}))
781781
.pipe(sourcemaps.write(".", { includeContent: false }))

scripts/tslint/booleanTriviaRule.ts

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,88 @@ export class Rule extends Lint.Rules.AbstractRule {
88
}
99

1010
function walk(ctx: Lint.WalkContext<void>): void {
11-
ts.forEachChild(ctx.sourceFile, recur);
12-
function recur(node: ts.Node): void {
11+
const { sourceFile } = ctx;
12+
ts.forEachChild(sourceFile, function recur(node: ts.Node): void {
1313
if (node.kind === ts.SyntaxKind.CallExpression) {
1414
checkCall(node as ts.CallExpression);
1515
}
1616
ts.forEachChild(node, recur);
17-
}
17+
});
1818

1919
function checkCall(node: ts.CallExpression): void {
20-
for (const arg of node.arguments) {
21-
if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) {
22-
continue;
20+
if (!shouldIgnoreCalledExpression(node.expression)) {
21+
for (const arg of node.arguments) {
22+
checkArg(arg);
2323
}
24+
}
25+
}
2426

25-
if (node.expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
26-
const methodName = (node.expression as ts.PropertyAccessExpression).name.text
27-
// Skip certain method names whose parameter names are not informative
28-
if (methodName === 'set' ||
29-
methodName === 'equal' ||
30-
methodName === 'fail' ||
31-
methodName === 'isTrue' ||
32-
methodName === 'assert') {
33-
continue;
34-
}
27+
/** Skip certain function/method names whose parameter names are not informative. */
28+
function shouldIgnoreCalledExpression(expression: ts.Expression): boolean {
29+
if (expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
30+
const methodName = (expression as ts.PropertyAccessExpression).name.text;
31+
if (methodName.indexOf("set") === 0) {
32+
return true;
3533
}
36-
else if (node.expression.kind === ts.SyntaxKind.Identifier) {
37-
const functionName = (node.expression as ts.Identifier).text;
38-
// Skip certain function names whose parameter names are not informative
39-
if (functionName === 'assert') {
40-
continue;
41-
}
34+
switch (methodName) {
35+
case "apply":
36+
case "assert":
37+
case "call":
38+
case "equal":
39+
case "fail":
40+
case "isTrue":
41+
case "output":
42+
case "stringify":
43+
return true;
4244
}
43-
44-
const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0);
45-
if (!(ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia)) {
46-
ctx.addFailureAtNode(arg, "Tag boolean argument with parameter name");
45+
}
46+
else if (expression.kind === ts.SyntaxKind.Identifier) {
47+
const functionName = (expression as ts.Identifier).text;
48+
if (functionName.indexOf("set") === 0) {
49+
return true;
50+
}
51+
switch (functionName) {
52+
case "assert":
53+
case "contains":
54+
case "createAnonymousType":
55+
case "createImportSpecifier":
56+
case "createProperty":
57+
case "createSignature":
58+
case "resolveName":
59+
return true;
4760
}
4861
}
62+
return false;
63+
}
64+
65+
function checkArg(arg: ts.Expression): void {
66+
if (!isTrivia(arg)) {
67+
return;
68+
}
69+
70+
const ranges = ts.getTrailingCommentRanges(sourceFile.text, arg.pos) || ts.getLeadingCommentRanges(sourceFile.text, arg.pos);
71+
if (ranges === undefined || ranges.length !== 1 || ranges[0].kind !== ts.SyntaxKind.MultiLineCommentTrivia) {
72+
ctx.addFailureAtNode(arg, "Tag boolean argument with parameter name");
73+
return;
74+
}
75+
76+
const range = ranges[0];
77+
const argStart = arg.getStart(sourceFile);
78+
if (range.end + 1 !== argStart && sourceFile.text.slice(range.end, argStart).indexOf("\n") === -1) {
79+
ctx.addFailureAtNode(arg, "There should be 1 space between an argument and its comment.");
80+
}
81+
}
82+
83+
function isTrivia(arg: ts.Expression): boolean {
84+
switch (arg.kind) {
85+
case ts.SyntaxKind.TrueKeyword:
86+
case ts.SyntaxKind.FalseKeyword:
87+
case ts.SyntaxKind.NullKeyword:
88+
return true;
89+
case ts.SyntaxKind.Identifier:
90+
return (arg as ts.Identifier).originalKeywordKind === ts.SyntaxKind.UndefinedKeyword;
91+
default:
92+
return false;
93+
}
4994
}
5095
}

src/compiler/binder.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ namespace ts {
418418
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
419419
}
420420
else {
421-
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
421+
return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
422422
}
423423
}
424424
else {
@@ -447,13 +447,13 @@ namespace ts {
447447
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
448448
(symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
449449
(symbolFlags & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0);
450-
const local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
450+
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
451451
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
452452
node.localSymbol = local;
453453
return local;
454454
}
455455
else {
456-
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
456+
return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
457457
}
458458
}
459459
}
@@ -1545,7 +1545,7 @@ namespace ts {
15451545
function declareSourceFileMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) {
15461546
return isExternalModule(file)
15471547
? declareModuleMember(node, symbolFlags, symbolExcludes)
1548-
: declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
1548+
: declareSymbol(file.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
15491549
}
15501550

15511551
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
@@ -1721,7 +1721,7 @@ namespace ts {
17211721
blockScopeContainer.locals = createMap<Symbol>();
17221722
addToContainerChain(blockScopeContainer);
17231723
}
1724-
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
1724+
declareSymbol(blockScopeContainer.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
17251725
}
17261726
}
17271727

@@ -2333,7 +2333,7 @@ namespace ts {
23332333

23342334
function bindThisPropertyAssignment(node: BinaryExpression) {
23352335
Debug.assert(isInJavaScriptFile(node));
2336-
const container = getThisContainer(node, /*includeArrowFunctions*/false);
2336+
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
23372337
switch (container.kind) {
23382338
case SyntaxKind.FunctionDeclaration:
23392339
case SyntaxKind.FunctionExpression:
@@ -2423,7 +2423,7 @@ namespace ts {
24232423
function bindCallExpression(node: CallExpression) {
24242424
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
24252425
// this check if we've already seen the module indicator
2426-
if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/false)) {
2426+
if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/ false)) {
24272427
setCommonJsModuleIndicator(node);
24282428
}
24292429
}

0 commit comments

Comments
 (0)