From ed5eca2b7b8307ea2a666d9d72c68720db44d076 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 11 Apr 2017 09:37:31 -0700 Subject: [PATCH] boolean-trivia lint rule: Enforce space between comment and argument --- Gulpfile.ts | 18 +-- scripts/tslint/booleanTriviaRule.ts | 129 ++++++++++-------- src/compiler/binder.ts | 6 +- src/compiler/checker.ts | 14 +- src/compiler/commandLineParser.ts | 2 +- src/compiler/moduleNameResolver.ts | 6 +- src/compiler/parser.ts | 6 +- src/compiler/program.ts | 2 +- src/harness/fourslash.ts | 4 +- src/harness/harnessLanguageService.ts | 2 +- .../unittests/cachingInServerLSHost.ts | 2 +- src/harness/unittests/moduleResolution.ts | 6 +- .../unittests/services/preProcessFile.ts | 24 ++-- .../unittests/tsserverProjectSystem.ts | 16 +-- src/server/editorServices.ts | 2 +- src/services/codefixes/fixAddMissingMember.ts | 2 +- src/services/codefixes/helpers.ts | 6 +- .../codefixes/unusedIdentifierFixes.ts | 2 +- src/services/completions.ts | 4 +- src/services/documentRegistry.ts | 2 +- src/services/goToImplementation.ts | 2 +- src/services/pathCompletions.ts | 12 +- src/services/services.ts | 6 +- 23 files changed, 147 insertions(+), 128 deletions(-) diff --git a/Gulpfile.ts b/Gulpfile.ts index 7a3cbb2538f..3fcd972db34 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -384,7 +384,7 @@ function prependCopyright(outputCopyright: boolean = !useDebugMode) { } gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => { - const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); + const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true)); return localCompilerProject.src() .pipe(newer(builtLocalCompiler)) .pipe(sourcemaps.init()) @@ -395,14 +395,14 @@ gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => { }); gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => { - const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false)); + const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/ false)); const {js, dts} = servicesProject.src() .pipe(newer(servicesFile)) .pipe(sourcemaps.init()) .pipe(servicesProject()); const completedJs = js.pipe(prependCopyright()) .pipe(sourcemaps.write(".")); - const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true)) + const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/ true)) .pipe(insert.transform((contents, file) => { file.path = standaloneDefinitionsFile; 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"], () => { // cancellationToken.js const cancellationTokenJs = path.join(builtLocalDirectory, "cancellationToken.js"); gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => { - const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); + const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true)); return cancellationTokenProject.src() .pipe(newer(cancellationTokenJs)) .pipe(sourcemaps.init()) @@ -442,7 +442,7 @@ gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => { // typingsInstallerFile.js const typingsInstallerJs = path.join(builtLocalDirectory, "typingsInstaller.js"); gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => { - const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); + const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true)); return cancellationTokenProject.src() .pipe(newer(typingsInstallerJs)) .pipe(sourcemaps.init()) @@ -455,7 +455,7 @@ gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => { const serverFile = path.join(builtLocalDirectory, "tsserver.js"); gulp.task(serverFile, /*help*/ false, [servicesFile, typingsInstallerJs, cancellationTokenJs], () => { - const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); + const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true)); return serverProject.src() .pipe(newer(serverFile)) .pipe(sourcemaps.init()) @@ -479,7 +479,7 @@ gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile], (done) => { js.pipe(prependCopyright()) .pipe(sourcemaps.write(".")) .pipe(gulp.dest("src/server")), - dts.pipe(prependCopyright(/*outputCopyright*/true)) + dts.pipe(prependCopyright(/*outputCopyright*/ true)) .pipe(insert.transform((content) => { return content + "\r\nexport = ts;\r\nexport as namespace ts;"; })) @@ -551,7 +551,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, /*help*/ false, [servicesFile], () => { - const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true)); + const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true)); return testProject.src() .pipe(newer(run)) .pipe(sourcemaps.init()) @@ -757,7 +757,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo browserify(intoStream(file.contents), { debug: true }) .bundle((err, res) => { // assumes file.contents is a Buffer - const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/true).toJSON()); + const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/ true).toJSON()); delete maps.sourceRoot; maps.sources = maps.sources.map(s => path.resolve(s === "_stream_0.js" ? "built/local/_stream_0.js" : s)); // Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths) diff --git a/scripts/tslint/booleanTriviaRule.ts b/scripts/tslint/booleanTriviaRule.ts index ee5f855e864..a2a44b7a48a 100644 --- a/scripts/tslint/booleanTriviaRule.ts +++ b/scripts/tslint/booleanTriviaRule.ts @@ -8,7 +8,8 @@ export class Rule extends Lint.Rules.AbstractRule { } function walk(ctx: Lint.WalkContext): void { - ts.forEachChild(ctx.sourceFile, function recur(node: ts.Node): void { + const { sourceFile } = ctx; + ts.forEachChild(sourceFile, function recur(node: ts.Node): void { if (node.kind === ts.SyntaxKind.CallExpression) { checkCall(node as ts.CallExpression); } @@ -16,61 +17,79 @@ function walk(ctx: Lint.WalkContext): void { }); function checkCall(node: ts.CallExpression): void { - for (const arg of node.arguments) { - switch (arg.kind) { - case ts.SyntaxKind.TrueKeyword: - case ts.SyntaxKind.FalseKeyword: - case ts.SyntaxKind.NullKeyword: - break; - case ts.SyntaxKind.Identifier: - if ((arg as ts.Identifier).originalKeywordKind !== ts.SyntaxKind.UndefinedKeyword) { - continue; - } - break; - default: - continue; - } - - 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.indexOf("set") === 0) { - continue; - } - switch (methodName) { - case "apply": - case "assert": - case "call": - case "equal": - case "fail": - case "isTrue": - case "output": - case "stringify": - continue; - } - } - 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.indexOf("set") === 0) { - continue; - } - switch (functionName) { - case "assert": - case "contains": - case "createAnonymousType": - case "createImportSpecifier": - case "createProperty": - case "createSignature": - case "resolveName": - continue; - } - } - - 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'); + if (!shouldIgnoreCalledExpression(node.expression)) { + for (const arg of node.arguments) { + checkArg(arg); } } } + + /** Skip certain function/method names whose parameter names are not informative. */ + function shouldIgnoreCalledExpression(expression: ts.Expression): boolean { + if (expression.kind === ts.SyntaxKind.PropertyAccessExpression) { + const methodName = (expression as ts.PropertyAccessExpression).name.text; + if (methodName.indexOf("set") === 0) { + return true; + } + switch (methodName) { + case "apply": + case "assert": + case "call": + case "equal": + case "fail": + case "isTrue": + case "output": + case "stringify": + return true; + } + } + else if (expression.kind === ts.SyntaxKind.Identifier) { + const functionName = (expression as ts.Identifier).text; + if (functionName.indexOf("set") === 0) { + return true; + } + switch (functionName) { + case "assert": + case "contains": + case "createAnonymousType": + case "createImportSpecifier": + case "createProperty": + case "createSignature": + case "resolveName": + return true; + } + } + return false; + } + + function checkArg(arg: ts.Expression): void { + if (!isTrivia(arg)) { + return; + } + + let ranges = ts.getTrailingCommentRanges(sourceFile.text, arg.pos) || ts.getLeadingCommentRanges(sourceFile.text, arg.pos); + if (ranges === undefined || ranges.length !== 1 || ranges[0].kind !== ts.SyntaxKind.MultiLineCommentTrivia) { + ctx.addFailureAtNode(arg, "Tag boolean argument with parameter name"); + return; + } + + const range = ranges[0]; + const argStart = arg.getStart(sourceFile); + if (range.end + 1 !== argStart && sourceFile.text.slice(range.end, argStart).indexOf("\n") === -1) { + ctx.addFailureAtNode(arg, "There should be 1 space between an argument and its comment."); + } + } + + function isTrivia(arg: ts.Expression): boolean { + switch (arg.kind) { + case ts.SyntaxKind.TrueKeyword: + case ts.SyntaxKind.FalseKeyword: + case ts.SyntaxKind.NullKeyword: + return true; + case ts.SyntaxKind.Identifier: + return (arg as ts.Identifier).originalKeywordKind === ts.SyntaxKind.UndefinedKeyword; + default: + return false; + } + } } diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 2477e909705..4e6a7a87afa 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -453,7 +453,7 @@ namespace ts { return local; } else { - return declareSymbol(container.locals, /*parent*/undefined, node, symbolFlags, symbolExcludes); + return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } } } @@ -2333,7 +2333,7 @@ namespace ts { function bindThisPropertyAssignment(node: BinaryExpression) { Debug.assert(isInJavaScriptFile(node)); - const container = getThisContainer(node, /*includeArrowFunctions*/false); + const container = getThisContainer(node, /*includeArrowFunctions*/ false); switch (container.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: @@ -2423,7 +2423,7 @@ namespace ts { function bindCallExpression(node: CallExpression) { // We're only inspecting call expressions to detect CommonJS modules, so we can skip // this check if we've already seen the module indicator - if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/false)) { + if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/ false)) { setCommonJsModuleIndicator(node); } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 343dc724286..aeae0de43fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2620,7 +2620,7 @@ namespace ts { propertyName, optionalToken, propertyTypeNode, - /*initializer*/undefined)); + /*initializer*/ undefined)); } } return typeElements.length ? typeElements : undefined; @@ -2754,7 +2754,7 @@ namespace ts { /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */ function getSymbolChain(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): Symbol[] | undefined { - let accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, /*useOnlyExternalAliasing*/false); + let accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, /*useOnlyExternalAliasing*/ false); let parentSymbol: Symbol; if (!accessibleSymbolChain || @@ -13386,7 +13386,7 @@ namespace ts { /// non-intrinsic elements' attributes type is the element instance type) function getJsxElementPropertiesName() { // JSX - const jsxNamespace = getGlobalSymbol(JsxNames.JSX, SymbolFlags.Namespace, /*diagnosticMessage*/undefined); + const jsxNamespace = getGlobalSymbol(JsxNames.JSX, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined); // JSX.ElementAttributesProperty [symbol] const attribsPropTypeSym = jsxNamespace && getSymbol(jsxNamespace.exports, JsxNames.ElementAttributesPropertyNameContainer, SymbolFlags.Type); // JSX.ElementAttributesProperty [type] @@ -15615,7 +15615,7 @@ namespace ts { } function isCommonJsRequire(node: Node) { - if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { + if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) { return false; } // Make sure require is not a local function @@ -17071,7 +17071,7 @@ namespace ts { function getTypeOfExpression(node: Expression, cache?: boolean) { // Optimize for the common case of a call to a function with a single non-generic call // signature where we can just fetch the return type without checking the arguments. - if (node.kind === SyntaxKind.CallExpression && (node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { + if (node.kind === SyntaxKind.CallExpression && (node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) { const funcType = checkNonNullExpression((node).expression); const signature = getSingleCallSignature(funcType); if (signature && !signature.typeParameters) { @@ -21859,7 +21859,7 @@ namespace ts { } else if (isTypeReferenceIdentifier(entityName)) { const meaning = (entityName.parent.kind === SyntaxKind.TypeReference || entityName.parent.kind === SyntaxKind.JSDocTypeReference) ? SymbolFlags.Type : SymbolFlags.Namespace; - return resolveEntityName(entityName, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/true); + return resolveEntityName(entityName, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true); } else if (entityName.parent.kind === SyntaxKind.JsxAttribute) { return getJsxAttributePropertySymbol(entityName.parent); @@ -22682,7 +22682,7 @@ namespace ts { ? SymbolFlags.Value | SymbolFlags.ExportValue : SymbolFlags.Type | SymbolFlags.Namespace; - const symbol = resolveEntityName(node, meaning, /*ignoreErrors*/true); + const symbol = resolveEntityName(node, meaning, /*ignoreErrors*/ true); return symbol && symbol !== unknownSymbol ? getTypeReferenceDirectivesForSymbol(symbol, meaning) : undefined; } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index a9df1d0d0b8..d5903b599b9 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1170,7 +1170,7 @@ namespace ts { const relativeDifference = convertToRelativePath(extendedDirname, basePath, getCanonicalFileName); const updatePath: (path: string) => string = path => isRootedDiskPath(path) ? path : combinePaths(relativeDifference, path); // Merge configs (copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios) - const result = parseJsonConfigFileContent(extendedResult.config, host, extendedDirname, /*existingOptions*/undefined, getBaseFileName(extendedConfigPath), resolutionStack.concat([resolvedPath])); + const result = parseJsonConfigFileContent(extendedResult.config, host, extendedDirname, /*existingOptions*/ undefined, getBaseFileName(extendedConfigPath), resolutionStack.concat([resolvedPath])); errors.push(...result.errors); const [include, exclude, files] = map(["include", "exclude", "files"], key => { if (!json[key] && extendedResult.config[key]) { diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 5280c794725..1603f08bb5f 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -656,7 +656,7 @@ namespace ts { // A path mapping may have a ".ts" extension; in contrast to an import, which should omit it. const tsExtension = tryGetExtensionFromPath(candidate); if (tsExtension !== undefined) { - const path = tryFile(candidate, failedLookupLocations, /*onlyRecordFailures*/false, state); + const path = tryFile(candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state); return path && { path, extension: tsExtension }; } @@ -694,7 +694,7 @@ namespace ts { return { resolvedModule: undefined, failedLookupLocations }; function tryResolve(extensions: Extensions): SearchResult<{ resolved: Resolved, isExternalLibraryImport: boolean }> { - const loader: ResolutionKindSpecificLoader = (extensions, candidate, failedLookupLocations, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, /*considerPackageJson*/true); + const loader: ResolutionKindSpecificLoader = (extensions, candidate, failedLookupLocations, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, /*considerPackageJson*/ true); const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loader, failedLookupLocations, state); if (resolved) { return toSearchResult({ resolved, isExternalLibraryImport: false }); @@ -710,7 +710,7 @@ namespace ts { } else { const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); - const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/true); + const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true); return resolved && toSearchResult({ resolved, isExternalLibraryImport: false }); } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c6fe2f79992..f76b1a071f2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3039,7 +3039,7 @@ namespace ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. const lastToken = token(); - arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "=>"); + arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, "=>"); arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) ? parseArrowFunctionExpressionBody(isAsync) : parseIdentifier(); @@ -3808,7 +3808,7 @@ namespace ts { // Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios // of one sort or another. if (inExpressionContext && token() === SyntaxKind.LessThanToken) { - const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElement(/*inExpressionContext*/true)); + const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true)); if (invalidElement) { parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element); const badNode = createNode(SyntaxKind.BinaryExpression, result.pos); @@ -5818,7 +5818,7 @@ namespace ts { } function processReferenceComments(sourceFile: SourceFile): void { - const triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, LanguageVariant.Standard, sourceText); + const triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ false, LanguageVariant.Standard, sourceText); const referencedFiles: FileReference[] = []; const typeReferenceDirectives: FileReference[] = []; const amdDependencies: { path: string; name: string }[] = []; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ae15ece684e..f2d44adb1f1 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1291,7 +1291,7 @@ namespace ts { } function collectRequireCalls(node: Node): void { - if (isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { + if (isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) { (imports || (imports = [])).push((node).arguments[0]); } else { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index db05f9f1ddf..5ed1162bd93 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -3787,11 +3787,11 @@ namespace FourSlashInterface { } public printCurrentFileStateWithWhitespace() { - this.state.printCurrentFileState(/*makeWhitespaceVisible*/true); + this.state.printCurrentFileState(/*makeWhitespaceVisible*/ true); } public printCurrentFileStateWithoutCaret() { - this.state.printCurrentFileState(/*makeWhitespaceVisible*/false, /*makeCaretVisible*/false); + this.state.printCurrentFileState(/*makeWhitespaceVisible*/ false, /*makeCaretVisible*/ false); } public printCurrentQuickInfo() { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index b736ca1be72..c6477240161 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -210,7 +210,7 @@ namespace Harness.LanguageService { } readDirectory(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[] { return ts.matchFiles(path, extensions, exclude, include, - /*useCaseSensitiveFileNames*/false, + /*useCaseSensitiveFileNames*/ false, this.getCurrentDirectory(), (p) => this.virtualFileSystem.getAccessibleFileSystemEntries(p)); } diff --git a/src/harness/unittests/cachingInServerLSHost.ts b/src/harness/unittests/cachingInServerLSHost.ts index e20288b8cd9..5389c8f37f8 100644 --- a/src/harness/unittests/cachingInServerLSHost.ts +++ b/src/harness/unittests/cachingInServerLSHost.ts @@ -65,7 +65,7 @@ namespace ts { }; const projectService = new server.ProjectService(serverHost, logger, { isCancellationRequested: () => false }, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined); - const rootScriptInfo = projectService.getOrCreateScriptInfo(rootFile, /* openedByClient */true, /*containingProject*/ undefined); + const rootScriptInfo = projectService.getOrCreateScriptInfo(rootFile, /*openedByClient*/ true, /*containingProject*/ undefined); const project = projectService.createInferredProjectWithRootFileIfNecessary(rootScriptInfo); project.setCompilerOptions({ module: ts.ModuleKind.AMD } ); return { diff --git a/src/harness/unittests/moduleResolution.ts b/src/harness/unittests/moduleResolution.ts index 4bb34cc2d03..14e13b60457 100644 --- a/src/harness/unittests/moduleResolution.ts +++ b/src/harness/unittests/moduleResolution.ts @@ -144,14 +144,14 @@ namespace ts { const resolution = nodeModuleNameResolver("b", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, packageJson, moduleFile, indexFile)); - checkResolvedModule(resolution.resolvedModule, createResolvedModule(indexPath, /*isExternalLibraryImport*/true)); + checkResolvedModule(resolution.resolvedModule, createResolvedModule(indexPath, /*isExternalLibraryImport*/ true)); } } it("module name as directory - handle invalid 'typings'", () => { testTypingsIgnored(["a", "b"]); testTypingsIgnored({ "a": "b" }); - testTypingsIgnored(/*typings*/true); + testTypingsIgnored(/*typings*/ true); testTypingsIgnored(/*typings*/ null); // tslint:disable-line no-null-keyword testTypingsIgnored(/*typings*/ undefined); }); @@ -530,7 +530,7 @@ import b = require("./moduleB"); check("m1", main, m1); check("m2", main, m2); check("m3", main, m3Typings); - check("m4", main, m4, /*isExternalLibraryImport*/true); + check("m4", main, m4, /*isExternalLibraryImport*/ true); function check(name: string, caller: File, expected: File, isExternalLibraryImport = false) { const result = resolveModuleName(name, caller.name, options, host); diff --git a/src/harness/unittests/services/preProcessFile.ts b/src/harness/unittests/services/preProcessFile.ts index b7d319a690f..65f68b8ca25 100644 --- a/src/harness/unittests/services/preProcessFile.ts +++ b/src/harness/unittests/services/preProcessFile.ts @@ -34,7 +34,7 @@ describe("PreProcessFile:", function () { describe("Test preProcessFiles,", function () { it("Correctly return referenced files from triple slash", function () { test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [{ fileName: "refFile1.ts", pos: 0, end: 37 }, { fileName: "refFile2.ts", pos: 38, end: 73 }, @@ -48,7 +48,7 @@ describe("PreProcessFile:", function () { it("Do not return reference path because of invalid triple-slash syntax", function () { test("///" + "\n" + "///" + "\n" + "///" + "\n" + "///", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [], @@ -61,7 +61,7 @@ describe("PreProcessFile:", function () { it("Correctly return imported files", function () { test("import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\"); import i3= require(\"r3.ts\"); import i4=require(\"r4.ts\"); import i5 = require (\"r5.ts\");", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [], @@ -88,7 +88,7 @@ describe("PreProcessFile:", function () { it("Do not return import path because of invalid import syntax", function () { test("import i1 require(\"r1.ts\"); import = require(\"r2.ts\") import i3= require(\"r3.ts\"); import i5", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [], @@ -101,7 +101,7 @@ describe("PreProcessFile:", function () { it("Correctly return referenced files and import files", function () { test("///" + "\n" + "///" + "\n" + "import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\");", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [{ fileName: "refFile1.ts", pos: 0, end: 35 }, { fileName: "refFile2.ts", pos: 36, end: 71 }], @@ -114,7 +114,7 @@ describe("PreProcessFile:", function () { it("Correctly return referenced files and import files even with some invalid syntax", function () { test("///" + "\n" + "///" + "\n" + "import i1 = require(\"r1.ts\"); import = require(\"r2.ts\"); import i2 = require(\"r3.ts\");", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [{ fileName: "refFile1.ts", pos: 0, end: 35 }], @@ -133,7 +133,7 @@ describe("PreProcessFile:", function () { "import {a as A} from \"m5\";" + "\n" + "import {a as A, b, c as C} from \"m6\";" + "\n" + "import def , {a, b, c as C} from \"m7\";" + "\n", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [], @@ -157,7 +157,7 @@ describe("PreProcessFile:", function () { "export {a} from \"m2\";" + "\n" + "export {a as A} from \"m3\";" + "\n" + "export {a as A, b, c as C} from \"m4\";" + "\n", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [], @@ -194,7 +194,7 @@ describe("PreProcessFile:", function () { it("Correctly handles export import declarations", function () { test("export import a = require(\"m1\");", - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ false, { referencedFiles: [], @@ -213,7 +213,7 @@ describe("PreProcessFile:", function () { foo(require('m3')); var z = { f: require('m4') } `, - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ true, { referencedFiles: [], @@ -233,7 +233,7 @@ describe("PreProcessFile:", function () { define(["mod1", "mod2"], (m1, m2) => { }); `, - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ true, { referencedFiles: [], @@ -251,7 +251,7 @@ describe("PreProcessFile:", function () { define("mod", ["mod1", "mod2"], (m1, m2) => { }); `, - /*readImportFile*/true, + /*readImportFile*/ true, /*detectJavaScriptImports*/ true, { referencedFiles: [], diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 10fb2832523..34e08f35699 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1795,9 +1795,9 @@ namespace ts.projectSystem { // Open HTML file projectService.applyChangesInOpenFiles( - /*openFiles*/[{ fileName: file2.path, hasMixedContent: true, scriptKind: ScriptKind.JS, content: `var hello = "hello";` }], - /*changedFiles*/undefined, - /*closedFiles*/undefined); + /*openFiles*/ [{ fileName: file2.path, hasMixedContent: true, scriptKind: ScriptKind.JS, content: `var hello = "hello";` }], + /*changedFiles*/ undefined, + /*closedFiles*/ undefined); // Now HTML file is included in the project checkNumberOfProjects(projectService, { configuredProjects: 1 }); @@ -1810,9 +1810,9 @@ namespace ts.projectSystem { // Close HTML file projectService.applyChangesInOpenFiles( - /*openFiles*/undefined, - /*changedFiles*/undefined, - /*closedFiles*/[file2.path]); + /*openFiles*/ undefined, + /*changedFiles*/ undefined, + /*closedFiles*/ [file2.path]); // HTML file is still included in project checkNumberOfProjects(projectService, { configuredProjects: 1 }); @@ -2270,12 +2270,12 @@ namespace ts.projectSystem { projectService.openClientFile(f1.path, "let x = 1;\nlet y = 2;"); projectService.checkNumberOfProjects({ externalProjects: 1 }); - projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path); + projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(f1.path); projectService.closeClientFile(f1.path); projectService.openClientFile(f1.path); projectService.checkNumberOfProjects({ externalProjects: 1 }); - const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path); + const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(f1.path); assert.equal(navbar[0].spans[0].length, f1.content.length); }); }); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 582c8974cec..00c81953ed4 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1091,7 +1091,7 @@ namespace ts.server { const { success, projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.getConfigFilePath()); if (!success) { // reset project settings to default - this.updateNonInferredProject(project, [], fileNamePropertyReader, {}, {}, /*compileOnSave*/false, configFileErrors); + this.updateNonInferredProject(project, [], fileNamePropertyReader, {}, {}, /*compileOnSave*/ false, configFileErrors); return configFileErrors; } diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index ec772e1e29e..a808786230d 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -118,7 +118,7 @@ namespace ts.codefix { stringTypeNode, /*initializer*/ undefined); const indexSignature = createIndexSignatureDeclaration( - /*decorators*/undefined, + /*decorators*/ undefined, /*modifiers*/ undefined, [indexingParameter], typeNode); diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index d9e1387e029..0de04d7a9b9 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -194,7 +194,7 @@ namespace ts.codefix { modifiers, name, optional, - /*typeParameters*/undefined, + /*typeParameters*/ undefined, parameters, /*returnType*/ undefined); } @@ -217,9 +217,9 @@ namespace ts.codefix { [createThrow( createNew( createIdentifier("Error"), - /*typeArguments*/undefined, + /*typeArguments*/ undefined, [createLiteral("Method not implemented.")]))], - /*multiline*/true); + /*multiline*/ true); } function createVisibilityModifier(flags: ModifierFlags) { diff --git a/src/services/codefixes/unusedIdentifierFixes.ts b/src/services/codefixes/unusedIdentifierFixes.ts index f77f9723d0f..0daeea5df62 100644 --- a/src/services/codefixes/unusedIdentifierFixes.ts +++ b/src/services/codefixes/unusedIdentifierFixes.ts @@ -116,7 +116,7 @@ namespace ts.codefix { const nextToken = getTokenAtPosition(sourceFile, importClause.name.end); if (nextToken && nextToken.kind === SyntaxKind.CommaToken) { // shift first non-whitespace position after comma to the start position of the node - return deleteRange({ pos: start, end: skipTrivia(sourceFile.text, nextToken.end, /*stopAfterLineBreaks*/ false, /*stopAtComments*/true) }); + return deleteRange({ pos: start, end: skipTrivia(sourceFile.text, nextToken.end, /*stopAfterLineBreaks*/ false, /*stopAtComments*/ true) }); } else { return deleteNode(importClause.name); diff --git a/src/services/completions.ts b/src/services/completions.ts index c0b8be80441..2073b950bee 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -211,7 +211,7 @@ namespace ts.Completions { const type = typeChecker.getContextualType((element.parent)); const entries: CompletionEntry[] = []; if (type) { - getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, element, /*performCharacterChecks*/false, typeChecker, target, log); + getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, element, /*performCharacterChecks*/ false, typeChecker, target, log); if (entries.length) { return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: true, entries }; } @@ -239,7 +239,7 @@ namespace ts.Completions { const type = typeChecker.getTypeAtLocation(node.expression); const entries: CompletionEntry[] = []; if (type) { - getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, node, /*performCharacterChecks*/false, typeChecker, target, log); + getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, node, /*performCharacterChecks*/ false, typeChecker, target, log); if (entries.length) { return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: true, entries }; } diff --git a/src/services/documentRegistry.ts b/src/services/documentRegistry.ts index 891a25db76a..fa1b50a6662 100644 --- a/src/services/documentRegistry.ts +++ b/src/services/documentRegistry.ts @@ -214,7 +214,7 @@ namespace ts { } function releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey): void { - const bucket = getBucketForCompilationSettings(key, /*createIfMissing*/false); + const bucket = getBucketForCompilationSettings(key, /*createIfMissing*/ false); Debug.assert(bucket !== undefined); const entry = bucket.get(path); diff --git a/src/services/goToImplementation.ts b/src/services/goToImplementation.ts index dd3c06174af..1d9f48ae5e8 100644 --- a/src/services/goToImplementation.ts +++ b/src/services/goToImplementation.ts @@ -18,7 +18,7 @@ namespace ts.GoToImplementation { else { // Perform "Find all References" and retrieve only those that are implementations const referencedSymbols = FindAllReferences.getReferencedSymbolsForNode(context, - node, sourceFiles, /*findInStrings*/false, /*findInComments*/false, /*isForRename*/false, /*implementations*/true); + node, sourceFiles, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/ false, /*implementations*/ true); const result = flatMap(referencedSymbols, symbol => symbol.references); return result && result.length > 0 ? result : undefined; diff --git a/src/services/pathCompletions.ts b/src/services/pathCompletions.ts index f47837a70f7..2b45457c147 100644 --- a/src/services/pathCompletions.ts +++ b/src/services/pathCompletions.ts @@ -12,11 +12,11 @@ namespace ts.Completions.PathCompletions { const extensions = getSupportedExtensions(compilerOptions); if (compilerOptions.rootDirs) { entries = getCompletionEntriesForDirectoryFragmentWithRootDirs( - compilerOptions.rootDirs, literalValue, scriptDirectory, extensions, /*includeExtensions*/false, span, compilerOptions, host, scriptPath); + compilerOptions.rootDirs, literalValue, scriptDirectory, extensions, /*includeExtensions*/ false, span, compilerOptions, host, scriptPath); } else { entries = getCompletionEntriesForDirectoryFragment( - literalValue, scriptDirectory, extensions, /*includeExtensions*/false, span, host, scriptPath); + literalValue, scriptDirectory, extensions, /*includeExtensions*/ false, span, host, scriptPath); } } else { @@ -94,7 +94,7 @@ namespace ts.Completions.PathCompletions { if (tryDirectoryExists(host, baseDirectory)) { // Enumerate the available files if possible - const files = tryReadDirectory(host, baseDirectory, extensions, /*exclude*/undefined, /*include*/["./*"]); + const files = tryReadDirectory(host, baseDirectory, extensions, /*exclude*/ undefined, /*include*/ ["./*"]); if (files) { /** @@ -153,7 +153,7 @@ namespace ts.Completions.PathCompletions { const fileExtensions = getSupportedExtensions(compilerOptions); const projectDir = compilerOptions.project || host.getCurrentDirectory(); const absolute = isRootedDiskPath(baseUrl) ? baseUrl : combinePaths(projectDir, baseUrl); - result = getCompletionEntriesForDirectoryFragment(fragment, normalizePath(absolute), fileExtensions, /*includeExtensions*/false, span, host); + result = getCompletionEntriesForDirectoryFragment(fragment, normalizePath(absolute), fileExtensions, /*includeExtensions*/ false, span, host); if (paths) { for (const path in paths) { @@ -267,7 +267,7 @@ namespace ts.Completions.PathCompletions { nonRelativeModules.push(visibleModule.moduleName); } else if (startsWith(visibleModule.moduleName, moduleNameFragment)) { - const nestedFiles = tryReadDirectory(host, visibleModule.moduleDir, supportedTypeScriptExtensions, /*exclude*/undefined, /*include*/["./*"]); + const nestedFiles = tryReadDirectory(host, visibleModule.moduleDir, supportedTypeScriptExtensions, /*exclude*/ undefined, /*include*/ ["./*"]); if (nestedFiles) { for (let f of nestedFiles) { f = normalizePath(f); @@ -327,7 +327,7 @@ namespace ts.Completions.PathCompletions { if (kind === "path") { // Give completions for a relative path const span: TextSpan = getDirectoryFragmentTextSpan(toComplete, range.pos + prefix.length); - completionInfo.entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(compilerOptions), /*includeExtensions*/true, span, host, sourceFile.path); + completionInfo.entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(compilerOptions), /*includeExtensions*/ true, span, host, sourceFile.path); } else { // Give completions based on the typings available diff --git a/src/services/services.ts b/src/services/services.ts index 3d108ac7fab..8ccc1d379d6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1472,17 +1472,17 @@ namespace ts { } function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] { - const referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments, /*isForRename*/true); + const referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments, /*isForRename*/ true); return FindAllReferences.convertReferences(referencedSymbols); } function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/false); + const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/ false); return FindAllReferences.convertReferences(referencedSymbols); } function findReferences(fileName: string, position: number): ReferencedSymbol[] { - const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/false); + const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/ false); // Only include referenced symbols that have a valid definition. return filter(referencedSymbols, rs => !!rs.definition); }