Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
fix adjacent-overload-signatures to treat static as non-overload (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nchen63 authored Nov 22, 2016
1 parent d29f484 commit 716e1e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/rules/adjacentOverloadSignaturesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker {
}

public visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void {
this.checkOverloadsAdjacent(node.members, (member) => member.name && getTextOfPropertyName(member.name));
this.checkOverloadsAdjacent(node.members, (member) => {
return getTextOfPropertyName(member);
});
super.visitInterfaceDeclaration(node);
}

Expand All @@ -84,7 +86,9 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker {
}

private visitMembers(members: Array<ts.TypeElement | ts.ClassElement>) {
this.checkOverloadsAdjacent(members, (member) => member.name && getTextOfPropertyName(member.name));
this.checkOverloadsAdjacent(members, (member) => {
return getTextOfPropertyName(member);
});
}

/** 'getOverloadName' may return undefined for nodes that cannot be overloads, e.g. a `const` declaration. */
Expand All @@ -109,19 +113,27 @@ function isLiteralExpression(node: ts.Node): node is ts.LiteralExpression {
return node.kind === ts.SyntaxKind.StringLiteral || node.kind === ts.SyntaxKind.NumericLiteral;
}

function getTextOfPropertyName(name: ts.PropertyName): string {
switch (name.kind) {
function getTextOfPropertyName(node: ts.InterfaceDeclaration | ts.TypeElement | ts.ClassElement): string {
let nameText: string;
if (node.name == null) {
return null;
}
switch (node.name.kind) {
case ts.SyntaxKind.Identifier:
return (name as ts.Identifier).text;
nameText = (node.name as ts.Identifier).text;
break;
case ts.SyntaxKind.ComputedPropertyName:
const { expression } = (name as ts.ComputedPropertyName);
const { expression } = (node.name as ts.ComputedPropertyName);
if (isLiteralExpression(expression)) {
return expression.text;
nameText = expression.text;
}
break;
default:
if (isLiteralExpression(name)) {
return name.text;
if (isLiteralExpression(node.name)) {
nameText = (<ts.StringLiteral> node.name).text;
}
}

const suffix = Lint.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword) ? " __static__" : "";
return nameText + suffix;
}
6 changes: 6 additions & 0 deletions test/rules/adjacent-overload-signatures/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,9 @@ declare namespace N {
export function a(x: number): void;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [All 'a' signatures should be adjacent]
}

class Foo {
public static bar() {}
constructor() {}
public bar() {}
}

0 comments on commit 716e1e7

Please sign in to comment.