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

Commit

Permalink
interface-over-type-literal: Convert to function (#2528)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson authored and adidahiya committed Apr 12, 2017
1 parent c04ebd9 commit a5999f8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/rules/interfaceOverTypeLiteralRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import { isTypeAliasDeclaration } from "tsutils";
import * as ts from "typescript";
import * as Lint from "../index";

Expand All @@ -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>): 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);
});
}

0 comments on commit a5999f8

Please sign in to comment.