Skip to content

Lint navigationBar.ts #8662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ function lintFileAsync(options, path, cb) {

var servicesLintTargets = [
"navigateTo.ts",
"navigationBar.ts",
"outliningElementsCollector.ts",
"patternMatcher.ts",
"services.ts",
Expand Down
72 changes: 36 additions & 36 deletions src/services/navigationBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace ts.NavigationBar {
}

function getChildNodes(nodes: Node[]): Node[] {
let childNodes: Node[] = [];
const childNodes: Node[] = [];

function visit(node: Node) {
switch (node.kind) {
Expand Down Expand Up @@ -109,7 +109,7 @@ namespace ts.NavigationBar {
}
}

//for (let i = 0, n = nodes.length; i < n; i++) {
// for (let i = 0, n = nodes.length; i < n; i++) {
// let node = nodes[i];

// if (node.kind === SyntaxKind.ClassDeclaration ||
Expand All @@ -123,13 +123,13 @@ namespace ts.NavigationBar {
// else if (node.kind === SyntaxKind.VariableStatement) {
// childNodes.push.apply(childNodes, (<VariableStatement>node).declarations);
// }
//}
// }
forEach(nodes, visit);
return sortNodes(childNodes);
}

function getTopLevelNodes(node: SourceFile): Node[] {
let topLevelNodes: Node[] = [];
const topLevelNodes: Node[] = [];
topLevelNodes.push(node);

addTopLevelNodes(node.statements, topLevelNodes);
Expand Down Expand Up @@ -157,7 +157,7 @@ namespace ts.NavigationBar {
function addTopLevelNodes(nodes: Node[], topLevelNodes: Node[]): void {
nodes = sortNodes(nodes);

for (let node of nodes) {
for (const node of nodes) {
switch (node.kind) {
case SyntaxKind.ClassDeclaration:
topLevelNodes.push(node);
Expand Down Expand Up @@ -198,7 +198,7 @@ namespace ts.NavigationBar {
}

function hasNamedFunctionDeclarations(nodes: NodeArray<Statement>): boolean {
for (let s of nodes) {
for (const s of nodes) {
if (s.kind === SyntaxKind.FunctionDeclaration && !isEmpty((<FunctionDeclaration>s).name.text)) {
return true;
}
Expand Down Expand Up @@ -238,17 +238,17 @@ namespace ts.NavigationBar {
}

function getItemsWorker(nodes: Node[], createItem: (n: Node) => ts.NavigationBarItem): ts.NavigationBarItem[] {
let items: ts.NavigationBarItem[] = [];
const items: ts.NavigationBarItem[] = [];

let keyToItem: Map<NavigationBarItem> = {};
const keyToItem: Map<NavigationBarItem> = {};

for (let child of nodes) {
let item = createItem(child);
for (const child of nodes) {
const item = createItem(child);
if (item !== undefined) {
if (item.text.length > 0) {
let key = item.text + "-" + item.kind + "-" + item.indent;
const key = item.text + "-" + item.kind + "-" + item.indent;

let itemWithSameName = keyToItem[key];
const itemWithSameName = keyToItem[key];
if (itemWithSameName) {
// We had an item with the same name. Merge these items together.
merge(itemWithSameName, item);
Expand All @@ -275,8 +275,8 @@ namespace ts.NavigationBar {

// Next, recursively merge or add any children in the source as appropriate.
outer:
for (let sourceChild of source.childItems) {
for (let targetChild of target.childItems) {
for (const sourceChild of source.childItems) {
for (const targetChild of target.childItems) {
if (targetChild.text === sourceChild.text && targetChild.kind === sourceChild.kind) {
// Found a match. merge them.
merge(targetChild, sourceChild);
Expand Down Expand Up @@ -383,7 +383,7 @@ namespace ts.NavigationBar {
return !text || text.trim() === "";
}

function getNavigationBarItem(text: string, kind: string, kindModifiers: string, spans: TextSpan[], childItems: NavigationBarItem[] = [], indent: number = 0): NavigationBarItem {
function getNavigationBarItem(text: string, kind: string, kindModifiers: string, spans: TextSpan[], childItems: NavigationBarItem[] = [], indent = 0): NavigationBarItem {
if (isEmpty(text)) {
return undefined;
}
Expand Down Expand Up @@ -437,7 +437,7 @@ namespace ts.NavigationBar {
}

// Otherwise, we need to aggregate each identifier to build up the qualified name.
let result: string[] = [];
const result: string[] = [];

result.push(moduleDeclaration.name.text);

Expand All @@ -451,9 +451,9 @@ namespace ts.NavigationBar {
}

function createModuleItem(node: ModuleDeclaration): NavigationBarItem {
let moduleName = getModuleName(node);
const moduleName = getModuleName(node);

let childItems = getItemsWorker(getChildNodes((<Block>getInnermostModule(node).body).statements), createChildItem);
const childItems = getItemsWorker(getChildNodes((<Block>getInnermostModule(node).body).statements), createChildItem);

return getNavigationBarItem(moduleName,
ts.ScriptElementKind.moduleElement,
Expand All @@ -465,9 +465,9 @@ namespace ts.NavigationBar {

function createFunctionItem(node: FunctionDeclaration): ts.NavigationBarItem {
if (node.body && node.body.kind === SyntaxKind.Block) {
let childItems = getItemsWorker(sortNodes((<Block>node.body).statements), createChildItem);
const childItems = getItemsWorker(sortNodes((<Block>node.body).statements), createChildItem);

return getNavigationBarItem(!node.name ? "default": node.name.text,
return getNavigationBarItem(!node.name ? "default" : node.name.text,
ts.ScriptElementKind.functionElement,
getNodeModifiers(node),
[getNodeSpan(node)],
Expand All @@ -489,7 +489,7 @@ namespace ts.NavigationBar {

function createMemberFunctionLikeItem(node: MethodDeclaration | ConstructorDeclaration): ts.NavigationBarItem {
if (node.body && node.body.kind === SyntaxKind.Block) {
let childItems = getItemsWorker(sortNodes((<Block>node.body).statements), createChildItem);
const childItems = getItemsWorker(sortNodes((<Block>node.body).statements), createChildItem);
let scriptElementKind: string;
let memberFunctionName: string;
if (node.kind === SyntaxKind.MethodDeclaration) {
Expand All @@ -513,16 +513,16 @@ namespace ts.NavigationBar {
}

function createSourceFileItem(node: SourceFile): ts.NavigationBarItem {
let childItems = getItemsWorker(getChildNodes(node.statements), createChildItem);
const childItems = getItemsWorker(getChildNodes(node.statements), createChildItem);

if (childItems === undefined || childItems.length === 0) {
return undefined;
}

hasGlobalNode = true;
let rootName = isExternalModule(node)
const rootName = isExternalModule(node)
? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName)))) + "\""
: "<global>"
: "<global>";

return getNavigationBarItem(rootName,
ts.ScriptElementKind.moduleElement,
Expand All @@ -535,22 +535,22 @@ namespace ts.NavigationBar {
let childItems: NavigationBarItem[];

if (node.members) {
let constructor = <ConstructorDeclaration>forEach(node.members, member => {
const constructor = <ConstructorDeclaration>forEach(node.members, member => {
return member.kind === SyntaxKind.Constructor && member;
});

// Add the constructor parameters in as children of the class (for property parameters).
// Note that *all non-binding pattern named* parameters will be added to the nodes array, but parameters that
// are not properties will be filtered out later by createChildItem.
let nodes: Node[] = removeDynamicallyNamedProperties(node);
const nodes: Node[] = removeDynamicallyNamedProperties(node);
if (constructor) {
addRange(nodes, filter(constructor.parameters, p => !isBindingPattern(p.name)));
}

childItems = getItemsWorker(sortNodes(nodes), createChildItem);
}

var nodeName = !node.name ? "default" : node.name.text;
const nodeName = !node.name ? "default" : node.name.text;

return getNavigationBarItem(
nodeName,
Expand All @@ -562,7 +562,7 @@ namespace ts.NavigationBar {
}

function createEnumItem(node: EnumDeclaration): ts.NavigationBarItem {
let childItems = getItemsWorker(sortNodes(removeComputedProperties(node)), createChildItem);
const childItems = getItemsWorker(sortNodes(removeComputedProperties(node)), createChildItem);
return getNavigationBarItem(
node.name.text,
ts.ScriptElementKind.enumElement,
Expand All @@ -573,7 +573,7 @@ namespace ts.NavigationBar {
}

function createInterfaceItem(node: InterfaceDeclaration): ts.NavigationBarItem {
let childItems = getItemsWorker(sortNodes(removeDynamicallyNamedProperties(node)), createChildItem);
const childItems = getItemsWorker(sortNodes(removeDynamicallyNamedProperties(node)), createChildItem);
return getNavigationBarItem(
node.name.text,
ts.ScriptElementKind.interfaceElement,
Expand All @@ -591,7 +591,7 @@ namespace ts.NavigationBar {
/**
* Like removeComputedProperties, but retains the properties with well known symbol names
*/
function removeDynamicallyNamedProperties(node: ClassDeclaration | InterfaceDeclaration): Declaration[]{
function removeDynamicallyNamedProperties(node: ClassDeclaration | InterfaceDeclaration): Declaration[] {
return filter<Declaration>(node.members, member => !hasDynamicName(member));
}

Expand Down Expand Up @@ -619,11 +619,11 @@ namespace ts.NavigationBar {
const anonClassText = "<class>";
let indent = 0;

let rootName = isExternalModule(sourceFile) ?
const rootName = isExternalModule(sourceFile) ?
"\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(sourceFile.fileName)))) + "\""
: "<global>";

let sourceFileItem = getNavBarItem(rootName, ScriptElementKind.moduleElement, [getNodeSpan(sourceFile)]);
const sourceFileItem = getNavBarItem(rootName, ScriptElementKind.moduleElement, [getNodeSpan(sourceFile)]);
let topItem = sourceFileItem;

// Walk the whole file, because we want to also find function expressions - which may be in variable initializer,
Expand Down Expand Up @@ -656,12 +656,12 @@ namespace ts.NavigationBar {
}
}

function createNavBarItem(node: Node) : NavigationBarItem {
function createNavBarItem(node: Node): NavigationBarItem {
switch (node.kind) {
case SyntaxKind.VariableDeclaration:
// Only add to the navbar if at the top-level of the file
// Note: "const" and "let" are also SyntaxKind.VariableDeclarations
if(node.parent/*VariableDeclarationList*/.parent/*VariableStatement*/
if (node.parent/*VariableDeclarationList*/.parent/*VariableStatement*/
.parent/*SourceFile*/.kind !== SyntaxKind.SourceFile) {
return undefined;
}
Expand Down Expand Up @@ -724,7 +724,7 @@ namespace ts.NavigationBar {
function getNavBarItem(text: string, kind: string, spans: TextSpan[], kindModifiers = ScriptElementKindModifier.none): NavigationBarItem {
return {
text, kind, kindModifiers, spans, childItems: [], indent, bolded: false, grayed: false
}
};
}

function getDefineModuleItem(node: Node): NavigationBarItem {
Expand All @@ -737,7 +737,7 @@ namespace ts.NavigationBar {
return undefined;
}
const callExpr = node.parent as CallExpression;
if (callExpr.expression.kind !== SyntaxKind.Identifier || callExpr.expression.getText() !== 'define') {
if (callExpr.expression.kind !== SyntaxKind.Identifier || callExpr.expression.getText() !== "define") {
return undefined;
}

Expand Down