Skip to content

Commit 0795c8d

Browse files
author
Andy
committed
Merge pull request #8662 from Microsoft/lint_navigation_bar
Lint navigationBar.ts
2 parents 780f251 + fffbbff commit 0795c8d

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

Diff for: Jakefile.js

+1
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ function lintFileAsync(options, path, cb) {
962962

963963
var servicesLintTargets = [
964964
"navigateTo.ts",
965+
"navigationBar.ts",
965966
"outliningElementsCollector.ts",
966967
"patternMatcher.ts",
967968
"services.ts",

Diff for: src/services/navigationBar.ts

+36-36
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace ts.NavigationBar {
4646
}
4747

4848
function getChildNodes(nodes: Node[]): Node[] {
49-
let childNodes: Node[] = [];
49+
const childNodes: Node[] = [];
5050

5151
function visit(node: Node) {
5252
switch (node.kind) {
@@ -109,7 +109,7 @@ namespace ts.NavigationBar {
109109
}
110110
}
111111

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

115115
// if (node.kind === SyntaxKind.ClassDeclaration ||
@@ -123,13 +123,13 @@ namespace ts.NavigationBar {
123123
// else if (node.kind === SyntaxKind.VariableStatement) {
124124
// childNodes.push.apply(childNodes, (<VariableStatement>node).declarations);
125125
// }
126-
//}
126+
// }
127127
forEach(nodes, visit);
128128
return sortNodes(childNodes);
129129
}
130130

131131
function getTopLevelNodes(node: SourceFile): Node[] {
132-
let topLevelNodes: Node[] = [];
132+
const topLevelNodes: Node[] = [];
133133
topLevelNodes.push(node);
134134

135135
addTopLevelNodes(node.statements, topLevelNodes);
@@ -157,7 +157,7 @@ namespace ts.NavigationBar {
157157
function addTopLevelNodes(nodes: Node[], topLevelNodes: Node[]): void {
158158
nodes = sortNodes(nodes);
159159

160-
for (let node of nodes) {
160+
for (const node of nodes) {
161161
switch (node.kind) {
162162
case SyntaxKind.ClassDeclaration:
163163
topLevelNodes.push(node);
@@ -198,7 +198,7 @@ namespace ts.NavigationBar {
198198
}
199199

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

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

243-
let keyToItem: Map<NavigationBarItem> = {};
243+
const keyToItem: Map<NavigationBarItem> = {};
244244

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

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

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

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

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

442442
result.push(moduleDeclaration.name.text);
443443

@@ -451,9 +451,9 @@ namespace ts.NavigationBar {
451451
}
452452

453453
function createModuleItem(node: ModuleDeclaration): NavigationBarItem {
454-
let moduleName = getModuleName(node);
454+
const moduleName = getModuleName(node);
455455

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

458458
return getNavigationBarItem(moduleName,
459459
ts.ScriptElementKind.moduleElement,
@@ -465,9 +465,9 @@ namespace ts.NavigationBar {
465465

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

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

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

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

518518
if (childItems === undefined || childItems.length === 0) {
519519
return undefined;
520520
}
521521

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

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

537537
if (node.members) {
538-
let constructor = <ConstructorDeclaration>forEach(node.members, member => {
538+
const constructor = <ConstructorDeclaration>forEach(node.members, member => {
539539
return member.kind === SyntaxKind.Constructor && member;
540540
});
541541

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

550550
childItems = getItemsWorker(sortNodes(nodes), createChildItem);
551551
}
552552

553-
var nodeName = !node.name ? "default" : node.name.text;
553+
const nodeName = !node.name ? "default" : node.name.text;
554554

555555
return getNavigationBarItem(
556556
nodeName,
@@ -562,7 +562,7 @@ namespace ts.NavigationBar {
562562
}
563563

564564
function createEnumItem(node: EnumDeclaration): ts.NavigationBarItem {
565-
let childItems = getItemsWorker(sortNodes(removeComputedProperties(node)), createChildItem);
565+
const childItems = getItemsWorker(sortNodes(removeComputedProperties(node)), createChildItem);
566566
return getNavigationBarItem(
567567
node.name.text,
568568
ts.ScriptElementKind.enumElement,
@@ -573,7 +573,7 @@ namespace ts.NavigationBar {
573573
}
574574

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

@@ -619,11 +619,11 @@ namespace ts.NavigationBar {
619619
const anonClassText = "<class>";
620620
let indent = 0;
621621

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

626-
let sourceFileItem = getNavBarItem(rootName, ScriptElementKind.moduleElement, [getNodeSpan(sourceFile)]);
626+
const sourceFileItem = getNavBarItem(rootName, ScriptElementKind.moduleElement, [getNodeSpan(sourceFile)]);
627627
let topItem = sourceFileItem;
628628

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

659-
function createNavBarItem(node: Node) : NavigationBarItem {
659+
function createNavBarItem(node: Node): NavigationBarItem {
660660
switch (node.kind) {
661661
case SyntaxKind.VariableDeclaration:
662662
// Only add to the navbar if at the top-level of the file
663663
// Note: "const" and "let" are also SyntaxKind.VariableDeclarations
664-
if(node.parent/*VariableDeclarationList*/.parent/*VariableStatement*/
664+
if (node.parent/*VariableDeclarationList*/.parent/*VariableStatement*/
665665
.parent/*SourceFile*/.kind !== SyntaxKind.SourceFile) {
666666
return undefined;
667667
}
@@ -724,7 +724,7 @@ namespace ts.NavigationBar {
724724
function getNavBarItem(text: string, kind: string, spans: TextSpan[], kindModifiers = ScriptElementKindModifier.none): NavigationBarItem {
725725
return {
726726
text, kind, kindModifiers, spans, childItems: [], indent, bolded: false, grayed: false
727-
}
727+
};
728728
}
729729

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

0 commit comments

Comments
 (0)