From e3bb5d3f288c132ad33a8aefd1b33481975c5479 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 4 Apr 2017 22:34:51 -0700 Subject: [PATCH 1/4] Update linting to avoid typechecking for booleanTriviaRule --- Gulpfile.ts | 46 ++++++++-------- scripts/tslint/booleanTriviaRule.ts | 54 ++++++++----------- src/compiler/checker.ts | 8 +-- src/compiler/commandLineParser.ts | 2 +- src/compiler/declarationEmitter.ts | 2 +- src/compiler/parser.ts | 2 +- src/compiler/sys.ts | 12 ++--- src/compiler/transformers/module/module.ts | 4 +- src/compiler/tsc.ts | 2 +- src/harness/compilerRunner.ts | 2 +- src/harness/fourslash.ts | 2 +- .../unittests/cachingInServerLSHost.ts | 2 +- src/harness/unittests/convertToBase64.ts | 2 +- src/harness/unittests/moduleResolution.ts | 2 +- src/harness/unittests/session.ts | 6 +-- .../unittests/tsserverProjectSystem.ts | 10 ++-- src/server/builder.ts | 2 +- src/server/server.ts | 2 +- src/server/session.ts | 14 ++--- src/services/codefixes/importFixes.ts | 4 +- src/services/completions.ts | 2 +- src/services/findAllReferences.ts | 2 +- src/services/formatting/formatting.ts | 2 +- src/services/jsTyping.ts | 4 +- src/services/shims.ts | 2 +- src/services/textChanges.ts | 2 +- src/services/utilities.ts | 2 +- tslint.json | 2 +- 28 files changed, 95 insertions(+), 103 deletions(-) diff --git a/Gulpfile.ts b/Gulpfile.ts index 022606e133b01..7b8c8f015a760 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -175,7 +175,7 @@ for (const i in libraryTargets) { const sources = [copyright].concat(entry.sources.map(function(s) { return path.join(libraryDirectory, s); })); - gulp.task(target, false, [], function() { + gulp.task(target, /*help*/ false, [], function() { return gulp.src(sources) .pipe(newer(target)) .pipe(concat(target, { newLine: "\n\n" })) @@ -275,7 +275,7 @@ function getCompilerSettings(base: tsc.Settings, useBuiltCompiler?: boolean): ts return copy; } -gulp.task(configureNightlyJs, false, [], () => { +gulp.task(configureNightlyJs, /*help*/ false, [], () => { const settings: tsc.Settings = { declaration: false, removeComments: true, @@ -304,7 +304,7 @@ const importDefinitelyTypedTestsDirectory = path.join(scriptsDirectory, "importD const importDefinitelyTypedTestsJs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.js"); const importDefinitelyTypedTestsTs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.ts"); -gulp.task(importDefinitelyTypedTestsJs, false, [], () => { +gulp.task(importDefinitelyTypedTestsJs, /*help*/ false, [], () => { const settings: tsc.Settings = getCompilerSettings({ declaration: false, removeComments: true, @@ -335,7 +335,7 @@ const generatedDiagnosticMessagesJSON = path.join(compilerDirectory, "diagnostic const builtGeneratedDiagnosticMessagesJSON = path.join(builtLocalDirectory, "diagnosticMessages.generated.json"); // processDiagnosticMessages script -gulp.task(processDiagnosticMessagesJs, false, [], () => { +gulp.task(processDiagnosticMessagesJs, /*help*/ false, [], () => { const settings: tsc.Settings = getCompilerSettings({ target: "es5", declaration: false, @@ -383,7 +383,7 @@ function prependCopyright(outputCopyright: boolean = !useDebugMode) { return insert.prepend(outputCopyright ? (copyrightContent || (copyrightContent = fs.readFileSync(copyright).toString())) : ""); } -gulp.task(builtLocalCompiler, false, [servicesFile], () => { +gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => { const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); return localCompilerProject.src() .pipe(newer(builtLocalCompiler)) @@ -394,7 +394,7 @@ gulp.task(builtLocalCompiler, false, [servicesFile], () => { .pipe(gulp.dest("src/compiler")); }); -gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => { +gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => { const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false)); const {js, dts} = servicesProject.src() .pipe(newer(servicesFile)) @@ -428,7 +428,7 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => { // cancellationToken.js const cancellationTokenJs = path.join(builtLocalDirectory, "cancellationToken.js"); -gulp.task(cancellationTokenJs, false, [servicesFile], () => { +gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => { const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); return cancellationTokenProject.src() .pipe(newer(cancellationTokenJs)) @@ -441,7 +441,7 @@ gulp.task(cancellationTokenJs, false, [servicesFile], () => { // typingsInstallerFile.js const typingsInstallerJs = path.join(builtLocalDirectory, "typingsInstaller.js"); -gulp.task(typingsInstallerJs, false, [servicesFile], () => { +gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => { const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); return cancellationTokenProject.src() .pipe(newer(typingsInstallerJs)) @@ -454,7 +454,7 @@ gulp.task(typingsInstallerJs, false, [servicesFile], () => { const serverFile = path.join(builtLocalDirectory, "tsserver.js"); -gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationTokenJs], () => { +gulp.task(serverFile, /*help*/ false, [servicesFile, typingsInstallerJs, cancellationTokenJs], () => { const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); return serverProject.src() .pipe(newer(serverFile)) @@ -468,7 +468,7 @@ gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationToke const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js"); const tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts"); -gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => { +gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile], (done) => { const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({}, /*useBuiltCompiler*/ true)); const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src() .pipe(sourcemaps.init()) @@ -497,7 +497,7 @@ const word2mdTs = path.join(scriptsDirectory, "word2md.ts"); const specWord = path.join(docDirectory, "TypeScript Language Specification.docx"); const specMd = path.join(docDirectory, "spec.md"); -gulp.task(word2mdJs, false, [], () => { +gulp.task(word2mdJs, /*help*/ false, [], () => { const settings: tsc.Settings = getCompilerSettings({ outFile: word2mdJs }, /*useBuiltCompiler*/ false); @@ -509,7 +509,7 @@ gulp.task(word2mdJs, false, [], () => { .pipe(gulp.dest(".")); }); -gulp.task(specMd, false, [word2mdJs], (done) => { +gulp.task(specMd, /*help*/ false, [word2mdJs], (done) => { const specWordFullPath = path.resolve(specWord); const specMDFullPath = path.resolve(specMd); const cmd = "cscript //nologo " + word2mdJs + " \"" + specWordFullPath + "\" " + "\"" + specMDFullPath + "\""; @@ -525,10 +525,10 @@ gulp.task("clean", "Cleans the compiler output, declare files, and tests", [], ( return del([builtDirectory]); }); -gulp.task("useDebugMode", false, [], (done) => { useDebugMode = true; done(); }); -gulp.task("dontUseDebugMode", false, [], (done) => { useDebugMode = false; done(); }); +gulp.task("useDebugMode", /*help*/ false, [], (done) => { useDebugMode = true; done(); }); +gulp.task("dontUseDebugMode", /*help*/ false, [], (done) => { useDebugMode = false; done(); }); -gulp.task("VerifyLKG", false, [], () => { +gulp.task("VerifyLKG", /*help*/ false, [], () => { const expectedFiles = [builtLocalCompiler, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile, typingsInstallerJs, cancellationTokenJs].concat(libraryTargets); const missingFiles = expectedFiles.filter(function(f) { return !fs.existsSync(f); @@ -541,7 +541,7 @@ gulp.task("VerifyLKG", false, [], () => { return gulp.src(expectedFiles).pipe(gulp.dest(LKGDirectory)); }); -gulp.task("LKGInternal", false, ["lib", "local"]); +gulp.task("LKGInternal", /*help*/ false, ["lib", "local"]); gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUseDebugMode"], () => { return runSequence("LKGInternal", "VerifyLKG"); @@ -550,7 +550,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse // Task to build the tests infrastructure using the built compiler const run = path.join(builtLocalDirectory, "run.js"); -gulp.task(run, false, [servicesFile], () => { +gulp.task(run, /*help*/ false, [servicesFile], () => { const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); return testProject.src() .pipe(newer(run)) @@ -724,7 +724,7 @@ gulp.task("runtests", const nodeServerOutFile = "tests/webTestServer.js"; const nodeServerInFile = "tests/webTestServer.ts"; -gulp.task(nodeServerOutFile, false, [servicesFile], () => { +gulp.task(nodeServerOutFile, /*help*/ false, [servicesFile], () => { const settings: tsc.Settings = getCompilerSettings({ module: "commonjs" }, /*useBuiltCompiler*/ true); return gulp.src(nodeServerInFile) .pipe(newer(nodeServerOutFile)) @@ -889,7 +889,7 @@ gulp.task("baseline-accept-test262", "Makes the most recent test262 test results // Webhost const webhostPath = "tests/webhost/webtsc.ts"; const webhostJsPath = "tests/webhost/webtsc.js"; -gulp.task(webhostJsPath, false, [servicesFile], () => { +gulp.task(webhostJsPath, /*help*/ false, [servicesFile], () => { const settings: tsc.Settings = getCompilerSettings({ outFile: webhostJsPath }, /*useBuiltCompiler*/ true); @@ -909,7 +909,7 @@ gulp.task("webhost", "Builds the tsc web host", [webhostJsPath], () => { // Perf compiler const perftscPath = "tests/perftsc.ts"; const perftscJsPath = "built/local/perftsc.js"; -gulp.task(perftscJsPath, false, [servicesFile], () => { +gulp.task(perftscJsPath, /*help*/ false, [servicesFile], () => { const settings: tsc.Settings = getCompilerSettings({ outFile: perftscJsPath }, /*useBuiltCompiler*/ true); @@ -927,10 +927,10 @@ gulp.task("perftsc", "Builds augmented version of the compiler for perf tests", // Instrumented compiler const loggedIOpath = path.join(harnessDirectory, "loggedIO.ts"); const loggedIOJsPath = path.join(builtLocalDirectory, "loggedIO.js"); -gulp.task(loggedIOJsPath, false, [], (done) => { +gulp.task(loggedIOJsPath, /*help*/ false, [], (done) => { const temp = path.join(builtLocalDirectory, "temp"); mkdirP(temp, (err) => { - if (err) { console.error(err); done(err); process.exit(1); }; + if (err) { console.error(err); done(err); process.exit(1); } exec(host, [LKGCompiler, "--types --outdir", temp, loggedIOpath], () => { fs.renameSync(path.join(temp, "/harness/loggedIO.js"), loggedIOJsPath); del(temp).then(() => done(), done); @@ -940,7 +940,7 @@ gulp.task(loggedIOJsPath, false, [], (done) => { const instrumenterPath = path.join(harnessDirectory, "instrumenter.ts"); const instrumenterJsPath = path.join(builtLocalDirectory, "instrumenter.js"); -gulp.task(instrumenterJsPath, false, [servicesFile], () => { +gulp.task(instrumenterJsPath, /*help*/ false, [servicesFile], () => { const settings: tsc.Settings = getCompilerSettings({ outFile: instrumenterJsPath }, /*useBuiltCompiler*/ true); diff --git a/scripts/tslint/booleanTriviaRule.ts b/scripts/tslint/booleanTriviaRule.ts index e79275c639205..b54bfc96821f0 100644 --- a/scripts/tslint/booleanTriviaRule.ts +++ b/scripts/tslint/booleanTriviaRule.ts @@ -2,20 +2,13 @@ import * as Lint from "tslint/lib"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { - public static FAILURE_STRING_FACTORY(name: string, currently?: string): string { - const current = currently ? ` (currently '${currently}')` : ""; - return `Tag boolean argument as '${name}'${current}`; - } - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { // Cheat to get type checker - const program = ts.createProgram([sourceFile.fileName], Lint.createCompilerOptions()); - const checker = program.getTypeChecker(); - return this.applyWithFunction(program.getSourceFile(sourceFile.fileName), ctx => walk(ctx, checker)); + return this.applyWithFunction(sourceFile, ctx => walk(ctx)); } } -function walk(ctx: Lint.WalkContext, checker: ts.TypeChecker): void { +function walk(ctx: Lint.WalkContext): void { ts.forEachChild(ctx.sourceFile, recur); function recur(node: ts.Node): void { if (node.kind === ts.SyntaxKind.CallExpression) { @@ -25,38 +18,37 @@ function walk(ctx: Lint.WalkContext, checker: ts.TypeChecker): void { } function checkCall(node: ts.CallExpression): void { - if (!node.arguments || !node.arguments.some(arg => arg.kind === ts.SyntaxKind.TrueKeyword || arg.kind === ts.SyntaxKind.FalseKeyword)) { - return; - } - - const targetCallSignature = checker.getResolvedSignature(node); - if (!targetCallSignature) { + if (!node.arguments) { return; } - const targetParameters = targetCallSignature.getParameters(); - for (let index = 0; index < targetParameters.length; index++) { - const param = targetParameters[index]; - const arg = node.arguments[index]; - if (!(arg && param)) { + for (const arg of node.arguments) { + if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) { continue; } - const argType = checker.getContextualType(arg); - if (argType && (argType.getFlags() & ts.TypeFlags.Boolean)) { - if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) { + if (node.expression.kind === ts.SyntaxKind.PropertyAccessExpression) { + const methodName = (node.expression as ts.PropertyAccessExpression).name.text + // Skip certain method names whose parameter names are not informative + if (methodName === 'set' || + methodName === 'equal' || + methodName === 'fail' || + methodName === 'isTrue' || + methodName === 'assert') { continue; } - let triviaContent: string | undefined; - const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0); - if (ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia) { - triviaContent = arg.getFullText().slice(ranges[0].pos + 2, ranges[0].end - 2); // +/-2 to remove /**/ + } + else if (node.expression.kind === ts.SyntaxKind.Identifier) { + const functionName = (node.expression as ts.Identifier).text; + // Skip certain function names whose parameter names are not informative + if (functionName === 'assert') { + continue; } + } - const paramName = param.getName(); - if (triviaContent !== paramName && triviaContent !== paramName + ":") { - ctx.addFailureAtNode(arg, Rule.FAILURE_STRING_FACTORY(param.getName(), triviaContent)); - } + const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0); + if (!(ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia)) { + ctx.addFailureAtNode(arg, 'Tag boolean argument with parameter name'); } } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7bdde91f28629..f0c1864c76348 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9680,7 +9680,7 @@ namespace ts { const original = getTypeOfSymbol(property); const updated = f(original); members.set(property.name, updated === original ? property : createSymbolWithType(property, updated)); - }; + } return members; } @@ -9724,7 +9724,7 @@ namespace ts { // Since get accessors already widen their return value there is no need to // widen accessor based properties here. members.set(prop.name, prop.flags & SymbolFlags.Property ? getWidenedProperty(prop) : prop); - }; + } const stringIndexInfo = getIndexInfoOfType(type, IndexKind.String); const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number); return createAnonymousType(type.symbol, members, emptyArray, emptyArray, @@ -15100,7 +15100,7 @@ namespace ts { if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) { break; } - const index = excludeArgument ? indexOf(excludeArgument, true) : -1; + const index = excludeArgument ? indexOf(excludeArgument, /*value*/ true) : -1; if (index < 0) { return candidate; } @@ -18728,7 +18728,7 @@ namespace ts { case SyntaxKind.ConstructorType: checkUnusedTypeParameters(node); break; - }; + } } } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 24abac1e298ec..acdfb180ea223 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1580,7 +1580,7 @@ namespace ts { delete wildcardDirectories[key]; } } - }; + } } return wildcardDirectories; diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 4a542ab30c7f4..2bd8d5971fb2f 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -590,7 +590,7 @@ namespace ts { currentIdentifiers = node.identifiers; isCurrentFileExternalModule = isExternalModule(node); enclosingDeclaration = node; - emitDetachedComments(currentText, currentLineMap, writer, writeCommentRange, node, newLine, true /* remove comments */); + emitDetachedComments(currentText, currentLineMap, writer, writeCommentRange, node, newLine, /*removeComents*/ true); emitLines(node.statements); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fcb85f4fbdc5b..6680e07f2d0d1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1845,7 +1845,7 @@ namespace ts { case ParsingContext.JSDocTupleTypes: return Diagnostics.Type_expected; case ParsingContext.JSDocRecordMembers: return Diagnostics.Property_assignment_expected; } - }; + } // Parses a comma-delimited list of elements function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): NodeArray { diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 5275d21017241..b65370076d279 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -54,10 +54,10 @@ namespace ts { referenceCount: number; } - declare var require: any; - declare var process: any; - declare var global: any; - declare var __filename: string; + declare const require: any; + declare const process: any; + declare const global: any; + declare const __filename: string; export function getNodeMajorVersion() { if (typeof process === "undefined") { @@ -74,7 +74,7 @@ namespace ts { return parseInt(version.substring(1, dot)); } - declare var ChakraHost: { + declare const ChakraHost: { args: string[]; currentDirectory: string; executingFile: string; @@ -368,7 +368,7 @@ namespace ts { if (eventName === "rename") { // When deleting a file, the passed baseFileName is null callback(!relativeFileName ? relativeFileName : normalizePath(combinePaths(directoryName, relativeFileName))); - }; + } } ); }, diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 81ed20bd4e037..4fe7b027e93a4 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1162,7 +1162,7 @@ namespace ts { statement = createStatement( createExportExpression( createIdentifier("__esModule"), - createLiteral(true) + createLiteral(/*value*/ true) ) ); } @@ -1175,7 +1175,7 @@ namespace ts { createIdentifier("exports"), createLiteral("__esModule"), createObjectLiteral([ - createPropertyAssignment("value", createLiteral(true)) + createPropertyAssignment("value", createLiteral(/*value*/ true)) ]) ] ) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 4fd3ecb02bb3c..780937a080c23 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -336,7 +336,7 @@ namespace ts { // is an absolute file name. directory == "" ? "." : directory, watchedDirectoryChanged, /*recursive*/ true); - }; + } } return configParseResult; } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 327932f366703..d0eee02efd7bf 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -51,7 +51,7 @@ class CompilerBaselineRunner extends RunnerBase { const path = ts.toPath(name, root, (fileName) => Harness.Compiler.getCanonicalFileName(fileName)); const pathStart = ts.toPath(Harness.IO.getCurrentDirectory(), "", (fileName) => Harness.Compiler.getCanonicalFileName(fileName)); return pathStart ? path.replace(pathStart, "/") : path; - }; + } public checkTestCodeOutput(fileName: string) { describe("compiler tests for " + fileName, () => { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 499c854b0910e..29d25c2a9c828 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1694,7 +1694,7 @@ namespace FourSlash { if (ch === "\r") { this.currentCaretPosition--; } - }; + } } private applyEdits(fileName: string, edits: ts.TextChange[], isFormattingEdit = false): number { diff --git a/src/harness/unittests/cachingInServerLSHost.ts b/src/harness/unittests/cachingInServerLSHost.ts index 5ea45d2a5f686..4107d8cfd14a3 100644 --- a/src/harness/unittests/cachingInServerLSHost.ts +++ b/src/harness/unittests/cachingInServerLSHost.ts @@ -123,7 +123,7 @@ namespace ts { try { // trigger synchronization to make sure that LSHost will try to find 'f2' module on disk project.getLanguageService().getSemanticDiagnostics(imported.name); - assert.isTrue(false, `should not find file '${imported.name}'`); + assert.fail(false, `should not find file '${imported.name}'`); } catch (e) { assert.isTrue(e.message.indexOf(`Could not find file: '${imported.name}'.`) === 0); diff --git a/src/harness/unittests/convertToBase64.ts b/src/harness/unittests/convertToBase64.ts index 09e38bdf674b1..975d21a38384b 100644 --- a/src/harness/unittests/convertToBase64.ts +++ b/src/harness/unittests/convertToBase64.ts @@ -22,7 +22,7 @@ namespace ts { }); it("Converts simple code snippet correctly", () => { - runTest(`/// + runTest(`/// var x: string = "string"; console.log(x);`); }); diff --git a/src/harness/unittests/moduleResolution.ts b/src/harness/unittests/moduleResolution.ts index aa30f1e01e2bd..5ea652573b6ca 100644 --- a/src/harness/unittests/moduleResolution.ts +++ b/src/harness/unittests/moduleResolution.ts @@ -151,7 +151,7 @@ namespace ts { it("module name as directory - handle invalid 'typings'", () => { testTypingsIgnored(["a", "b"]); testTypingsIgnored({ "a": "b" }); - testTypingsIgnored(true); + testTypingsIgnored(/*typings*/true); /* tslint:disable no-null-keyword */ testTypingsIgnored(null); /* tslint:enable no-null-keyword */ diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index d3ea153e235cb..9a38de7da1089 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -326,7 +326,7 @@ namespace ts.server { send(msg: protocol.Message) { this.lastSent = msg; } - }; + } it("can override methods such as send", () => { const session = new TestSession(); @@ -367,7 +367,7 @@ namespace ts.server { assert(this.projectService); expect(this.projectService).to.be.instanceOf(ProjectService); } - }; + } new ServiceSession(); }); }); @@ -462,7 +462,7 @@ namespace ts.server { }); this.callbacks[this.seq] = callback; } - }; + } it("can be constructed and respond to commands", (done) => { const cli = new InProcClient(); diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index b78fa094571a8..29b2d108f788a 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -174,7 +174,7 @@ namespace ts.projectSystem { request.type = "request"; return this.executeCommand(request); } - }; + } export function createSession(host: server.ServerHost, typingsInstaller?: server.ITypingsInstaller, projectServiceEventHandler?: server.ProjectServiceEventHandler, cancellationToken?: server.ServerCancellationToken, throttleWaitMilliseconds?: number) { if (typingsInstaller === undefined) { @@ -381,7 +381,7 @@ namespace ts.projectSystem { fileExists(s: string) { const path = this.toPath(s); return this.fs.contains(path) && isFile(this.fs.get(path)); - }; + } getFileSize(s: string) { const path = this.toPath(s); @@ -476,11 +476,11 @@ namespace ts.projectSystem { // TOOD: record and invoke callbacks to simulate timer events setTimeout(callback: TimeOutCallback, _time: number, ...args: any[]) { return this.timeoutCallbacks.register(callback, args); - }; + } clearTimeout(timeoutId: any): void { this.timeoutCallbacks.unregister(timeoutId); - }; + } checkTimeoutQueueLength(expected: number) { const callbacksCount = this.timeoutCallbacks.count(); @@ -501,7 +501,7 @@ namespace ts.projectSystem { clearImmediate(timeoutId: any): void { this.immediateCallbacks.unregister(timeoutId); - }; + } createDirectory(directoryName: string): void { this.createFileOrFolder({ path: directoryName }); diff --git a/src/server/builder.ts b/src/server/builder.ts index 108c0a0c64b31..bfd4f4ac8983e 100644 --- a/src/server/builder.ts +++ b/src/server/builder.ts @@ -191,7 +191,7 @@ namespace ts.server { const l = lf.scriptInfo.fileName; const r = rf.scriptInfo.fileName; return (l < r ? -1 : (l > r ? 1 : 0)); - }; + } static addToReferenceList(array: ModuleBuilderFileInfo[], fileInfo: ModuleBuilderFileInfo) { if (array.length === 0) { diff --git a/src/server/server.ts b/src/server/server.ts index e38f82f35f6f0..ab746f44f5b72 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -718,7 +718,7 @@ namespace ts.server { } catch (e) { cancellationToken = nullCancellationToken; - }; + } let eventPort: number; { diff --git a/src/server/session.ts b/src/server/session.ts index 4cdddc831a159..d01f51cf6c3d0 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -300,7 +300,7 @@ namespace ts.server { } } - private setTimerHandle(timerHandle: any) {; + private setTimerHandle(timerHandle: any) { if (this.timerHandle !== undefined) { this.operationHost.getServerHost().clearTimeout(this.timerHandle); } @@ -1544,17 +1544,17 @@ namespace ts.server { [CommandNames.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => { this.projectService.openExternalProject(request.arguments, /*suppressRefreshOfInferredProjects*/ false); // TODO: report errors - return this.requiredResponse(true); + return this.requiredResponse(/*response*/ true); }, [CommandNames.OpenExternalProjects]: (request: protocol.OpenExternalProjectsRequest) => { this.projectService.openExternalProjects(request.arguments.projects); // TODO: report errors - return this.requiredResponse(true); + return this.requiredResponse(/*response*/ true); }, [CommandNames.CloseExternalProject]: (request: protocol.CloseExternalProjectRequest) => { this.projectService.closeExternalProject(request.arguments.projectFileName); // TODO: report errors - return this.requiredResponse(true); + return this.requiredResponse(/*response*/ true); }, [CommandNames.SynchronizeProjectList]: (request: protocol.SynchronizeProjectListRequest) => { const result = this.projectService.synchronizeProjectList(request.arguments.knownProjects); @@ -1578,7 +1578,7 @@ namespace ts.server { this.projectService.applyChangesInOpenFiles(request.arguments.openFiles, request.arguments.changedFiles, request.arguments.closedFiles); this.changeSeq++; // TODO: report errors - return this.requiredResponse(true); + return this.requiredResponse(/*response*/ true); }, [CommandNames.Exit]: () => { this.exit(); @@ -1689,7 +1689,7 @@ namespace ts.server { }, [CommandNames.Cleanup]: () => { this.cleanup(); - return this.requiredResponse(true); + return this.requiredResponse(/*response*/ true); }, [CommandNames.SemanticDiagnosticsSync]: (request: protocol.SemanticDiagnosticsSyncRequest) => { return this.requiredResponse(this.getSemanticDiagnosticsSync(request.arguments)); @@ -1763,7 +1763,7 @@ namespace ts.server { }, [CommandNames.CompilerOptionsForInferredProjects]: (request: protocol.SetCompilerOptionsForInferredProjectsRequest) => { this.setCompilerOptionsForInferredProjects(request.arguments); - return this.requiredResponse(true); + return this.requiredResponse(/*response*/ true); }, [CommandNames.ProjectInfo]: (request: protocol.ProjectInfoRequest) => { return this.requiredResponse(this.getProjectInfo(request.arguments)); diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 0c1511ff1ebdb..e10794997cafe 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -542,12 +542,12 @@ namespace ts.codefix { } function getRelativePathIfInDirectory(path: string, directoryPath: string) { - const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, false); + const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); return isRootedDiskPath(relativePath) || startsWith(relativePath, "..") ? undefined : relativePath; } function getRelativePath(path: string, directoryPath: string) { - const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, false); + const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); return moduleHasNonRelativeName(relativePath) ? "./" + relativePath : relativePath; } } diff --git a/src/services/completions.ts b/src/services/completions.ts index 67890a9b00090..c0b8be8044169 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -173,7 +173,7 @@ namespace ts.Completions { // a['/*completion position*/'] return getStringLiteralCompletionEntriesFromElementAccess(node.parent, typeChecker, compilerOptions.target, log); } - else if (node.parent.kind === SyntaxKind.ImportDeclaration || isExpressionOfExternalModuleImportEqualsDeclaration(node) || isRequireCall(node.parent, false)) { + else if (node.parent.kind === SyntaxKind.ImportDeclaration || isExpressionOfExternalModuleImportEqualsDeclaration(node) || isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) { // Get all known external module names or complete a path to a module // i.e. import * as ns from "/*completion position*/"; // import x = require("/*completion position*/"); diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 5a471fb6f356c..70fa8e8bc2327 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -701,7 +701,7 @@ namespace ts.FindAllReferences { } }); } - }; + } return result; } diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 4fa3b71a3a200..a29023af882dd 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -568,7 +568,7 @@ namespace ts.formatting { function getEffectiveDelta(delta: number, child: TextRangeWithKind) { // Delta value should be zero when the node explicitly prevents indentation of the child node - return SmartIndenter.nodeWillIndentChild(node, child, true) ? delta : 0; + return SmartIndenter.nodeWillIndentChild(node, child, /*indentByDefault*/ true) ? delta : 0; } } diff --git a/src/services/jsTyping.ts b/src/services/jsTyping.ts index c11f6e67a71a6..1c03974247004 100644 --- a/src/services/jsTyping.ts +++ b/src/services/jsTyping.ts @@ -13,7 +13,7 @@ namespace ts.JsTyping { fileExists: (fileName: string) => boolean; readFile: (path: string, encoding?: string) => string; readDirectory: (rootDir: string, extensions: string[], excludes: string[], includes: string[], depth?: number) => string[]; - }; + } interface PackageJson { _requiredBy?: string[]; @@ -23,7 +23,7 @@ namespace ts.JsTyping { optionalDependencies?: MapLike; peerDependencies?: MapLike; typings?: string; - }; + } // A map of loose file names to library names // that we are confident require typings diff --git a/src/services/shims.ts b/src/services/shims.ts index de2fd39b8a837..8cb864d983ac9 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -1226,7 +1226,7 @@ namespace ts { // Here we expose the TypeScript services as an external module // so that it may be consumed easily like a node module. - declare var module: any; + declare const module: any; if (typeof module !== "undefined" && module.exports) { module.exports = ts; } diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index afc989274959a..d7056cfdca241 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -421,7 +421,7 @@ namespace ts.textChanges { let changesInFile = changesPerFile.get(c.sourceFile.path); if (!changesInFile) { changesPerFile.set(c.sourceFile.path, changesInFile = []); - }; + } changesInFile.push(c); } // convert changes diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 2c48cd79b9b15..d1f127d4ebc78 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1334,7 +1334,7 @@ namespace ts { name.charCodeAt(0) === name.charCodeAt(length - 1) && (name.charCodeAt(0) === CharacterCodes.doubleQuote || name.charCodeAt(0) === CharacterCodes.singleQuote)) { return name.substring(1, length - 1); - }; + } return name; } diff --git a/tslint.json b/tslint.json index be722309a242a..bf1d9bbf8b958 100644 --- a/tslint.json +++ b/tslint.json @@ -50,7 +50,7 @@ "check-else" ], "no-internal-module": true, - "no-trailing-whitespace": true, + "no-trailing-whitespace": [true, "ignore-template-strings"], "no-inferrable-types": true, "no-null-keyword": true, "boolean-trivia": true, From a1be5a4d686ee8b90b6526a191ffe9394a129e7e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 5 Apr 2017 07:34:12 -0700 Subject: [PATCH 2/4] Update cachingInServerLSHost.ts --- src/harness/unittests/cachingInServerLSHost.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/harness/unittests/cachingInServerLSHost.ts b/src/harness/unittests/cachingInServerLSHost.ts index 4107d8cfd14a3..e20288b8cd99a 100644 --- a/src/harness/unittests/cachingInServerLSHost.ts +++ b/src/harness/unittests/cachingInServerLSHost.ts @@ -123,7 +123,7 @@ namespace ts { try { // trigger synchronization to make sure that LSHost will try to find 'f2' module on disk project.getLanguageService().getSemanticDiagnostics(imported.name); - assert.fail(false, `should not find file '${imported.name}'`); + assert.isTrue(false, `should not find file '${imported.name}'`); } catch (e) { assert.isTrue(e.message.indexOf(`Could not find file: '${imported.name}'.`) === 0); @@ -203,4 +203,4 @@ namespace ts { assert.isTrue(diags.length === 0); }); }); -} \ No newline at end of file +} From 40393c59eae6afca8df8f83561004f963ff056fa Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 5 Apr 2017 07:35:03 -0700 Subject: [PATCH 3/4] Update booleanTriviaRule.ts --- scripts/tslint/booleanTriviaRule.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/tslint/booleanTriviaRule.ts b/scripts/tslint/booleanTriviaRule.ts index b54bfc96821f0..0115606053f6e 100644 --- a/scripts/tslint/booleanTriviaRule.ts +++ b/scripts/tslint/booleanTriviaRule.ts @@ -18,10 +18,6 @@ function walk(ctx: Lint.WalkContext): void { } function checkCall(node: ts.CallExpression): void { - if (!node.arguments) { - return; - } - for (const arg of node.arguments) { if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) { continue; @@ -52,4 +48,4 @@ function walk(ctx: Lint.WalkContext): void { } } } -} \ No newline at end of file +} From 008cd89c0daf3fd30933cbfe652f5e20405bf987 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 5 Apr 2017 11:29:47 -0700 Subject: [PATCH 4/4] Update booleanTriviaRule.ts --- scripts/tslint/booleanTriviaRule.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/tslint/booleanTriviaRule.ts b/scripts/tslint/booleanTriviaRule.ts index 0115606053f6e..25d001ed9cdc1 100644 --- a/scripts/tslint/booleanTriviaRule.ts +++ b/scripts/tslint/booleanTriviaRule.ts @@ -3,7 +3,6 @@ import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - // Cheat to get type checker return this.applyWithFunction(sourceFile, ctx => walk(ctx)); } }