Skip to content

Commit d8a24e3

Browse files
Merge pull request #15021 from RyanCavanaugh/lintFixes
Update linting to avoid typechecking for booleanTriviaRule
2 parents 2b61d18 + 008cd89 commit d8a24e3

28 files changed

+95
-108
lines changed

Gulpfile.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ for (const i in libraryTargets) {
175175
const sources = [copyright].concat(entry.sources.map(function(s) {
176176
return path.join(libraryDirectory, s);
177177
}));
178-
gulp.task(target, false, [], function() {
178+
gulp.task(target, /*help*/ false, [], function() {
179179
return gulp.src(sources)
180180
.pipe(newer(target))
181181
.pipe(concat(target, { newLine: "\n\n" }))
@@ -275,7 +275,7 @@ function getCompilerSettings(base: tsc.Settings, useBuiltCompiler?: boolean): ts
275275
return copy;
276276
}
277277

278-
gulp.task(configureNightlyJs, false, [], () => {
278+
gulp.task(configureNightlyJs, /*help*/ false, [], () => {
279279
const settings: tsc.Settings = {
280280
declaration: false,
281281
removeComments: true,
@@ -304,7 +304,7 @@ const importDefinitelyTypedTestsDirectory = path.join(scriptsDirectory, "importD
304304
const importDefinitelyTypedTestsJs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.js");
305305
const importDefinitelyTypedTestsTs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.ts");
306306

307-
gulp.task(importDefinitelyTypedTestsJs, false, [], () => {
307+
gulp.task(importDefinitelyTypedTestsJs, /*help*/ false, [], () => {
308308
const settings: tsc.Settings = getCompilerSettings({
309309
declaration: false,
310310
removeComments: true,
@@ -335,7 +335,7 @@ const generatedDiagnosticMessagesJSON = path.join(compilerDirectory, "diagnostic
335335
const builtGeneratedDiagnosticMessagesJSON = path.join(builtLocalDirectory, "diagnosticMessages.generated.json");
336336

337337
// processDiagnosticMessages script
338-
gulp.task(processDiagnosticMessagesJs, false, [], () => {
338+
gulp.task(processDiagnosticMessagesJs, /*help*/ false, [], () => {
339339
const settings: tsc.Settings = getCompilerSettings({
340340
target: "es5",
341341
declaration: false,
@@ -383,7 +383,7 @@ function prependCopyright(outputCopyright: boolean = !useDebugMode) {
383383
return insert.prepend(outputCopyright ? (copyrightContent || (copyrightContent = fs.readFileSync(copyright).toString())) : "");
384384
}
385385

386-
gulp.task(builtLocalCompiler, false, [servicesFile], () => {
386+
gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
387387
const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
388388
return localCompilerProject.src()
389389
.pipe(newer(builtLocalCompiler))
@@ -394,7 +394,7 @@ gulp.task(builtLocalCompiler, false, [servicesFile], () => {
394394
.pipe(gulp.dest("src/compiler"));
395395
});
396396

397-
gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
397+
gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
398398
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false));
399399
const {js, dts} = servicesProject.src()
400400
.pipe(newer(servicesFile))
@@ -428,7 +428,7 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
428428

429429
// cancellationToken.js
430430
const cancellationTokenJs = path.join(builtLocalDirectory, "cancellationToken.js");
431-
gulp.task(cancellationTokenJs, false, [servicesFile], () => {
431+
gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => {
432432
const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
433433
return cancellationTokenProject.src()
434434
.pipe(newer(cancellationTokenJs))
@@ -441,7 +441,7 @@ gulp.task(cancellationTokenJs, false, [servicesFile], () => {
441441

442442
// typingsInstallerFile.js
443443
const typingsInstallerJs = path.join(builtLocalDirectory, "typingsInstaller.js");
444-
gulp.task(typingsInstallerJs, false, [servicesFile], () => {
444+
gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => {
445445
const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
446446
return cancellationTokenProject.src()
447447
.pipe(newer(typingsInstallerJs))
@@ -454,7 +454,7 @@ gulp.task(typingsInstallerJs, false, [servicesFile], () => {
454454

455455
const serverFile = path.join(builtLocalDirectory, "tsserver.js");
456456

457-
gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationTokenJs], () => {
457+
gulp.task(serverFile, /*help*/ false, [servicesFile, typingsInstallerJs, cancellationTokenJs], () => {
458458
const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
459459
return serverProject.src()
460460
.pipe(newer(serverFile))
@@ -468,7 +468,7 @@ gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationToke
468468
const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
469469
const tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
470470

471-
gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
471+
gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile], (done) => {
472472
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
473473
const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src()
474474
.pipe(sourcemaps.init())
@@ -497,7 +497,7 @@ const word2mdTs = path.join(scriptsDirectory, "word2md.ts");
497497
const specWord = path.join(docDirectory, "TypeScript Language Specification.docx");
498498
const specMd = path.join(docDirectory, "spec.md");
499499

500-
gulp.task(word2mdJs, false, [], () => {
500+
gulp.task(word2mdJs, /*help*/ false, [], () => {
501501
const settings: tsc.Settings = getCompilerSettings({
502502
outFile: word2mdJs
503503
}, /*useBuiltCompiler*/ false);
@@ -509,7 +509,7 @@ gulp.task(word2mdJs, false, [], () => {
509509
.pipe(gulp.dest("."));
510510
});
511511

512-
gulp.task(specMd, false, [word2mdJs], (done) => {
512+
gulp.task(specMd, /*help*/ false, [word2mdJs], (done) => {
513513
const specWordFullPath = path.resolve(specWord);
514514
const specMDFullPath = path.resolve(specMd);
515515
const cmd = "cscript //nologo " + word2mdJs + " \"" + specWordFullPath + "\" " + "\"" + specMDFullPath + "\"";
@@ -525,10 +525,10 @@ gulp.task("clean", "Cleans the compiler output, declare files, and tests", [], (
525525
return del([builtDirectory]);
526526
});
527527

528-
gulp.task("useDebugMode", false, [], (done) => { useDebugMode = true; done(); });
529-
gulp.task("dontUseDebugMode", false, [], (done) => { useDebugMode = false; done(); });
528+
gulp.task("useDebugMode", /*help*/ false, [], (done) => { useDebugMode = true; done(); });
529+
gulp.task("dontUseDebugMode", /*help*/ false, [], (done) => { useDebugMode = false; done(); });
530530

531-
gulp.task("VerifyLKG", false, [], () => {
531+
gulp.task("VerifyLKG", /*help*/ false, [], () => {
532532
const expectedFiles = [builtLocalCompiler, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile, typingsInstallerJs, cancellationTokenJs].concat(libraryTargets);
533533
const missingFiles = expectedFiles.filter(function(f) {
534534
return !fs.existsSync(f);
@@ -541,7 +541,7 @@ gulp.task("VerifyLKG", false, [], () => {
541541
return gulp.src(expectedFiles).pipe(gulp.dest(LKGDirectory));
542542
});
543543

544-
gulp.task("LKGInternal", false, ["lib", "local"]);
544+
gulp.task("LKGInternal", /*help*/ false, ["lib", "local"]);
545545

546546
gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUseDebugMode"], () => {
547547
return runSequence("LKGInternal", "VerifyLKG");
@@ -550,7 +550,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
550550

551551
// Task to build the tests infrastructure using the built compiler
552552
const run = path.join(builtLocalDirectory, "run.js");
553-
gulp.task(run, false, [servicesFile], () => {
553+
gulp.task(run, /*help*/ false, [servicesFile], () => {
554554
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
555555
return testProject.src()
556556
.pipe(newer(run))
@@ -724,7 +724,7 @@ gulp.task("runtests",
724724

725725
const nodeServerOutFile = "tests/webTestServer.js";
726726
const nodeServerInFile = "tests/webTestServer.ts";
727-
gulp.task(nodeServerOutFile, false, [servicesFile], () => {
727+
gulp.task(nodeServerOutFile, /*help*/ false, [servicesFile], () => {
728728
const settings: tsc.Settings = getCompilerSettings({ module: "commonjs" }, /*useBuiltCompiler*/ true);
729729
return gulp.src(nodeServerInFile)
730730
.pipe(newer(nodeServerOutFile))
@@ -889,7 +889,7 @@ gulp.task("baseline-accept-test262", "Makes the most recent test262 test results
889889
// Webhost
890890
const webhostPath = "tests/webhost/webtsc.ts";
891891
const webhostJsPath = "tests/webhost/webtsc.js";
892-
gulp.task(webhostJsPath, false, [servicesFile], () => {
892+
gulp.task(webhostJsPath, /*help*/ false, [servicesFile], () => {
893893
const settings: tsc.Settings = getCompilerSettings({
894894
outFile: webhostJsPath
895895
}, /*useBuiltCompiler*/ true);
@@ -909,7 +909,7 @@ gulp.task("webhost", "Builds the tsc web host", [webhostJsPath], () => {
909909
// Perf compiler
910910
const perftscPath = "tests/perftsc.ts";
911911
const perftscJsPath = "built/local/perftsc.js";
912-
gulp.task(perftscJsPath, false, [servicesFile], () => {
912+
gulp.task(perftscJsPath, /*help*/ false, [servicesFile], () => {
913913
const settings: tsc.Settings = getCompilerSettings({
914914
outFile: perftscJsPath
915915
}, /*useBuiltCompiler*/ true);
@@ -927,10 +927,10 @@ gulp.task("perftsc", "Builds augmented version of the compiler for perf tests",
927927
// Instrumented compiler
928928
const loggedIOpath = path.join(harnessDirectory, "loggedIO.ts");
929929
const loggedIOJsPath = path.join(builtLocalDirectory, "loggedIO.js");
930-
gulp.task(loggedIOJsPath, false, [], (done) => {
930+
gulp.task(loggedIOJsPath, /*help*/ false, [], (done) => {
931931
const temp = path.join(builtLocalDirectory, "temp");
932932
mkdirP(temp, (err) => {
933-
if (err) { console.error(err); done(err); process.exit(1); };
933+
if (err) { console.error(err); done(err); process.exit(1); }
934934
exec(host, [LKGCompiler, "--types --outdir", temp, loggedIOpath], () => {
935935
fs.renameSync(path.join(temp, "/harness/loggedIO.js"), loggedIOJsPath);
936936
del(temp).then(() => done(), done);
@@ -940,7 +940,7 @@ gulp.task(loggedIOJsPath, false, [], (done) => {
940940

941941
const instrumenterPath = path.join(harnessDirectory, "instrumenter.ts");
942942
const instrumenterJsPath = path.join(builtLocalDirectory, "instrumenter.js");
943-
gulp.task(instrumenterJsPath, false, [servicesFile], () => {
943+
gulp.task(instrumenterJsPath, /*help*/ false, [servicesFile], () => {
944944
const settings: tsc.Settings = getCompilerSettings({
945945
outFile: instrumenterJsPath
946946
}, /*useBuiltCompiler*/ true);

scripts/tslint/booleanTriviaRule.ts

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@ import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44
export class Rule extends Lint.Rules.AbstractRule {
5-
public static FAILURE_STRING_FACTORY(name: string, currently?: string): string {
6-
const current = currently ? ` (currently '${currently}')` : "";
7-
return `Tag boolean argument as '${name}'${current}`;
8-
}
9-
105
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
11-
// Cheat to get type checker
12-
const program = ts.createProgram([sourceFile.fileName], Lint.createCompilerOptions());
13-
const checker = program.getTypeChecker();
14-
return this.applyWithFunction(program.getSourceFile(sourceFile.fileName), ctx => walk(ctx, checker));
6+
return this.applyWithFunction(sourceFile, ctx => walk(ctx));
157
}
168
}
179

18-
function walk(ctx: Lint.WalkContext<void>, checker: ts.TypeChecker): void {
10+
function walk(ctx: Lint.WalkContext<void>): void {
1911
ts.forEachChild(ctx.sourceFile, recur);
2012
function recur(node: ts.Node): void {
2113
if (node.kind === ts.SyntaxKind.CallExpression) {
@@ -25,39 +17,34 @@ function walk(ctx: Lint.WalkContext<void>, checker: ts.TypeChecker): void {
2517
}
2618

2719
function checkCall(node: ts.CallExpression): void {
28-
if (!node.arguments || !node.arguments.some(arg => arg.kind === ts.SyntaxKind.TrueKeyword || arg.kind === ts.SyntaxKind.FalseKeyword)) {
29-
return;
30-
}
31-
32-
const targetCallSignature = checker.getResolvedSignature(node);
33-
if (!targetCallSignature) {
34-
return;
35-
}
36-
37-
const targetParameters = targetCallSignature.getParameters();
38-
for (let index = 0; index < targetParameters.length; index++) {
39-
const param = targetParameters[index];
40-
const arg = node.arguments[index];
41-
if (!(arg && param)) {
20+
for (const arg of node.arguments) {
21+
if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) {
4222
continue;
4323
}
4424

45-
const argType = checker.getContextualType(arg);
46-
if (argType && (argType.getFlags() & ts.TypeFlags.Boolean)) {
47-
if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) {
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') {
4833
continue;
4934
}
50-
let triviaContent: string | undefined;
51-
const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0);
52-
if (ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia) {
53-
triviaContent = arg.getFullText().slice(ranges[0].pos + 2, ranges[0].end - 2); // +/-2 to remove /**/
35+
}
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;
5441
}
42+
}
5543

56-
const paramName = param.getName();
57-
if (triviaContent !== paramName && triviaContent !== paramName + ":") {
58-
ctx.addFailureAtNode(arg, Rule.FAILURE_STRING_FACTORY(param.getName(), triviaContent));
59-
}
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');
6047
}
6148
}
6249
}
63-
}
50+
}

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9709,7 +9709,7 @@ namespace ts {
97099709
const original = getTypeOfSymbol(property);
97109710
const updated = f(original);
97119711
members.set(property.name, updated === original ? property : createSymbolWithType(property, updated));
9712-
};
9712+
}
97139713
return members;
97149714
}
97159715

@@ -9753,7 +9753,7 @@ namespace ts {
97539753
// Since get accessors already widen their return value there is no need to
97549754
// widen accessor based properties here.
97559755
members.set(prop.name, prop.flags & SymbolFlags.Property ? getWidenedProperty(prop) : prop);
9756-
};
9756+
}
97579757
const stringIndexInfo = getIndexInfoOfType(type, IndexKind.String);
97589758
const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number);
97599759
return createAnonymousType(type.symbol, members, emptyArray, emptyArray,
@@ -15129,7 +15129,7 @@ namespace ts {
1512915129
if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
1513015130
break;
1513115131
}
15132-
const index = excludeArgument ? indexOf(excludeArgument, true) : -1;
15132+
const index = excludeArgument ? indexOf(excludeArgument, /*value*/ true) : -1;
1513315133
if (index < 0) {
1513415134
return candidate;
1513515135
}
@@ -18757,7 +18757,7 @@ namespace ts {
1875718757
case SyntaxKind.ConstructorType:
1875818758
checkUnusedTypeParameters(<FunctionLikeDeclaration>node);
1875918759
break;
18760-
};
18760+
}
1876118761
}
1876218762
}
1876318763
}

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ namespace ts {
15801580
delete wildcardDirectories[key];
15811581
}
15821582
}
1583-
};
1583+
}
15841584
}
15851585

15861586
return wildcardDirectories;

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ namespace ts {
590590
currentIdentifiers = node.identifiers;
591591
isCurrentFileExternalModule = isExternalModule(node);
592592
enclosingDeclaration = node;
593-
emitDetachedComments(currentText, currentLineMap, writer, writeCommentRange, node, newLine, true /* remove comments */);
593+
emitDetachedComments(currentText, currentLineMap, writer, writeCommentRange, node, newLine, /*removeComents*/ true);
594594
emitLines(node.statements);
595595
}
596596

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ namespace ts {
18451845
case ParsingContext.JSDocTupleTypes: return Diagnostics.Type_expected;
18461846
case ParsingContext.JSDocRecordMembers: return Diagnostics.Property_assignment_expected;
18471847
}
1848-
};
1848+
}
18491849

18501850
// Parses a comma-delimited list of elements
18511851
function parseDelimitedList<T extends Node>(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): NodeArray<T> {

src/compiler/sys.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ namespace ts {
5454
referenceCount: number;
5555
}
5656

57-
declare var require: any;
58-
declare var process: any;
59-
declare var global: any;
60-
declare var __filename: string;
57+
declare const require: any;
58+
declare const process: any;
59+
declare const global: any;
60+
declare const __filename: string;
6161

6262
export function getNodeMajorVersion() {
6363
if (typeof process === "undefined") {
@@ -74,7 +74,7 @@ namespace ts {
7474
return parseInt(version.substring(1, dot));
7575
}
7676

77-
declare var ChakraHost: {
77+
declare const ChakraHost: {
7878
args: string[];
7979
currentDirectory: string;
8080
executingFile: string;
@@ -368,7 +368,7 @@ namespace ts {
368368
if (eventName === "rename") {
369369
// When deleting a file, the passed baseFileName is null
370370
callback(!relativeFileName ? relativeFileName : normalizePath(combinePaths(directoryName, relativeFileName)));
371-
};
371+
}
372372
}
373373
);
374374
},

src/compiler/transformers/module/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ namespace ts {
11621162
statement = createStatement(
11631163
createExportExpression(
11641164
createIdentifier("__esModule"),
1165-
createLiteral(true)
1165+
createLiteral(/*value*/ true)
11661166
)
11671167
);
11681168
}
@@ -1175,7 +1175,7 @@ namespace ts {
11751175
createIdentifier("exports"),
11761176
createLiteral("__esModule"),
11771177
createObjectLiteral([
1178-
createPropertyAssignment("value", createLiteral(true))
1178+
createPropertyAssignment("value", createLiteral(/*value*/ true))
11791179
])
11801180
]
11811181
)

0 commit comments

Comments
 (0)