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

member-access: Skip index signature, it can not have an access modifier #2437

Merged
merged 1 commit into from
Mar 30, 2017
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
14 changes: 6 additions & 8 deletions src/rules/memberAccessRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ export class Rule extends Lint.Rules.AbstractRule {
}

function walk(ctx: Lint.WalkContext<void>, noPublic: boolean, checkAccessor: boolean, checkConstructor: boolean) {
return ts.forEachChild(ctx.sourceFile, recur);
function recur(node: ts.Node): void {
return ts.forEachChild(ctx.sourceFile, function recur(node: ts.Node): void {
if (isClassLikeDeclaration(node)) {
for (const child of node.members) {
if (shouldCheck(child)) {
Expand All @@ -84,7 +83,7 @@ function walk(ctx: Lint.WalkContext<void>, noPublic: boolean, checkAccessor: boo
}
}
return ts.forEachChild(node, recur);
}
});

function shouldCheck(node: ts.ClassElement): boolean {
switch (node.kind) {
Expand All @@ -93,10 +92,11 @@ function walk(ctx: Lint.WalkContext<void>, noPublic: boolean, checkAccessor: boo
case ts.SyntaxKind.GetAccessor:
case ts.SyntaxKind.SetAccessor:
return checkAccessor;
case ts.SyntaxKind.SemicolonClassElement:
return false;
default:
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.PropertyDeclaration:
return true;
default:
return false;
}
}

Expand Down Expand Up @@ -131,8 +131,6 @@ function memberType(node: ts.ClassElement): string {
return "get property accessor";
case ts.SyntaxKind.SetAccessor:
return "set property accessor";
case ts.SyntaxKind.IndexSignature:
return "index signature";
default:
throw new Error("unhandled node type " + ts.SyntaxKind[node.kind]);
}
Expand Down
1 change: 0 additions & 1 deletion test/rules/member-access/default/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ declare class AmbientAccess {

class Members {
[x: string]: number;
~~~~~~~~~~~~~~~~~~~~ [The index signature must be marked either 'private', 'public', or 'protected']
i: number;
~ [The class property 'i' must be marked either 'private', 'public', or 'protected']
static j: number;
Expand Down