From a5999f8b93a4946839beb1c79b2b730003c23b28 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 11 Apr 2017 22:05:59 -0700 Subject: [PATCH] interface-over-type-literal: Convert to function (#2528) --- src/rules/interfaceOverTypeLiteralRule.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/rules/interfaceOverTypeLiteralRule.ts b/src/rules/interfaceOverTypeLiteralRule.ts index a25b9facf48..ede77d5f49d 100644 --- a/src/rules/interfaceOverTypeLiteralRule.ts +++ b/src/rules/interfaceOverTypeLiteralRule.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { isTypeAliasDeclaration } from "tsutils"; import * as ts from "typescript"; import * as Lint from "../index"; @@ -35,15 +36,15 @@ export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING = "Use an interface instead of a type literal."; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new InterfaceOverTypeLiteralWalker(sourceFile, this.getOptions())); + return this.applyWithFunction(sourceFile, walk); } } -class InterfaceOverTypeLiteralWalker extends Lint.RuleWalker { - public visitTypeAliasDeclaration(node: ts.TypeAliasDeclaration) { - if (node.type.kind === ts.SyntaxKind.TypeLiteral) { - this.addFailureAtNode(node.name, Rule.FAILURE_STRING); +function walk(ctx: Lint.WalkContext): void { + return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void { + if (isTypeAliasDeclaration(node) && node.type.kind === ts.SyntaxKind.TypeLiteral) { + ctx.addFailureAtNode(node.name, Rule.FAILURE_STRING); } - super.visitTypeAliasDeclaration(node); - } + return ts.forEachChild(node, cb); + }); }