From f9eb330b198360e4134873b5cba58de67fde7df0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 28 Dec 2015 16:58:20 -0500 Subject: [PATCH] Lint 'navigateTo.ts'. --- Jakefile.js | 6 ++++- src/services/navigateTo.ts | 48 +++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index b81596cfbfb..ad904fc3ea4 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -921,7 +921,11 @@ function lintFileAsync(options, path, cb) { }); } -var servicesLintTargets = ["services.ts", "outliningElementsCollector.ts"].map(function (s) { +var servicesLintTargets = [ + "services.ts", + "outliningElementsCollector.ts", + "navigateTo.ts", +].map(function (s) { return path.join(servicesDirectory, s); }); var lintTargets = compilerSources diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index 2a0abba8695..8022e2fad7a 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -3,19 +3,19 @@ namespace ts.NavigateTo { type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration }; export function getNavigateToItems(program: Program, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[] { - let patternMatcher = createPatternMatcher(searchValue); + const patternMatcher = createPatternMatcher(searchValue); let rawItems: RawNavigateToItem[] = []; // This means "compare in a case insensitive manner." - let baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" }; + const baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" }; // Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[] forEach(program.getSourceFiles(), sourceFile => { cancellationToken.throwIfCancellationRequested(); - let nameToDeclarations = sourceFile.getNamedDeclarations(); - for (let name in nameToDeclarations) { - let declarations = getProperty(nameToDeclarations, name); + const nameToDeclarations = sourceFile.getNamedDeclarations(); + for (const name in nameToDeclarations) { + const declarations = getProperty(nameToDeclarations, name); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. @@ -25,11 +25,11 @@ namespace ts.NavigateTo { continue; } - for (let declaration of declarations) { + for (const declaration of declarations) { // It was a match! If the pattern has dots in it, then also see if the // declaration container matches as well. if (patternMatcher.patternContainsDots) { - let containers = getContainers(declaration); + const containers = getContainers(declaration); if (!containers) { return undefined; } @@ -41,8 +41,8 @@ namespace ts.NavigateTo { } } - let fileName = sourceFile.fileName; - let matchKind = bestMatchKind(matches); + const fileName = sourceFile.fileName; + const matchKind = bestMatchKind(matches); rawItems.push({ name, fileName, matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration }); } } @@ -54,7 +54,7 @@ namespace ts.NavigateTo { rawItems = rawItems.slice(0, maxResultCount); } - let items = map(rawItems, createNavigateToItem); + const items = map(rawItems, createNavigateToItem); return items; @@ -62,7 +62,7 @@ namespace ts.NavigateTo { Debug.assert(matches.length > 0); // This is a case sensitive match, only if all the submatches were case sensitive. - for (let match of matches) { + for (const match of matches) { if (!match.isCaseSensitive) { return false; } @@ -86,16 +86,16 @@ namespace ts.NavigateTo { function tryAddSingleDeclarationName(declaration: Declaration, containers: string[]) { if (declaration && declaration.name) { - let text = getTextOfIdentifierOrLiteral(declaration.name); + const text = getTextOfIdentifierOrLiteral(declaration.name); if (text !== undefined) { containers.unshift(text); } else if (declaration.name.kind === SyntaxKind.ComputedPropertyName) { - return tryAddComputedPropertyName((declaration.name).expression, containers, /*includeLastPortion:*/ true); + return tryAddComputedPropertyName((declaration.name).expression, containers, /*includeLastPortion*/ true); } else { // Don't know how to add this. - return false + return false; } } @@ -106,7 +106,7 @@ namespace ts.NavigateTo { // // [X.Y.Z]() { } function tryAddComputedPropertyName(expression: Expression, containers: string[], includeLastPortion: boolean): boolean { - let text = getTextOfIdentifierOrLiteral(expression); + const text = getTextOfIdentifierOrLiteral(expression); if (text !== undefined) { if (includeLastPortion) { containers.unshift(text); @@ -115,24 +115,24 @@ namespace ts.NavigateTo { } if (expression.kind === SyntaxKind.PropertyAccessExpression) { - let propertyAccess = expression; + const propertyAccess = expression; if (includeLastPortion) { containers.unshift(propertyAccess.name.text); } - return tryAddComputedPropertyName(propertyAccess.expression, containers, /*includeLastPortion:*/ true); + return tryAddComputedPropertyName(propertyAccess.expression, containers, /*includeLastPortion*/ true); } return false; } function getContainers(declaration: Declaration) { - let containers: string[] = []; + const containers: string[] = []; // First, if we started with a computed property name, then add all but the last // portion into the container array. if (declaration.name.kind === SyntaxKind.ComputedPropertyName) { - if (!tryAddComputedPropertyName((declaration.name).expression, containers, /*includeLastPortion:*/ false)) { + if (!tryAddComputedPropertyName((declaration.name).expression, containers, /*includeLastPortion*/ false)) { return undefined; } } @@ -155,8 +155,8 @@ namespace ts.NavigateTo { Debug.assert(matches.length > 0); let bestMatchKind = PatternMatchKind.camelCase; - for (let match of matches) { - let kind = match.kind; + for (const match of matches) { + const kind = match.kind; if (kind < bestMatchKind) { bestMatchKind = kind; } @@ -171,13 +171,13 @@ namespace ts.NavigateTo { // We first sort case insensitively. So "Aaa" will come before "bar". // Then we sort case sensitively, so "aaa" will come before "Aaa". return i1.matchKind - i2.matchKind || - i1.name.localeCompare(i2.name, undefined, baseSensitivity) || + i1.name.localeCompare(i2.name, undefined, baseSensitivity) || i1.name.localeCompare(i2.name); } function createNavigateToItem(rawItem: RawNavigateToItem): NavigateToItem { - let declaration = rawItem.declaration; - let container = getContainerNode(declaration); + const declaration = rawItem.declaration; + const container = getContainerNode(declaration); return { name: rawItem.name, kind: getNodeKind(declaration),