Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
convert no-for-in rule to use walk function
Browse files Browse the repository at this point in the history
  • Loading branch information
drexler committed Dec 18, 2018
1 parent a59b4fc commit f1707e7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/noForInRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ export class Rule extends Lint.Rules.AbstractRule {
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoForInRuleWalker(sourceFile, this.getOptions()));
return this.applyWithFunction(sourceFile, walk);
}
}

class NoForInRuleWalker extends Lint.RuleWalker {
protected visitForInStatement(node: ts.ForInStatement): void {
const initializer: string = node.initializer.getText();
const expression: string = node.expression.getText();
function walk(ctx: Lint.WalkContext<void>) {
function cb(node: ts.Node): void {
if (node.kind === ts.SyntaxKind.ForInStatement) {
const initializer: string = (<ts.ForInStatement>node).initializer.getText();
const expression: string = (<ts.ForInStatement>node).expression.getText();

const msg: string = Rule.FAILURE_STRING_FACTORY(initializer, expression);
this.addFailureAt(node.getStart(), node.getWidth(), msg);
const msg: string = Rule.FAILURE_STRING_FACTORY(initializer, expression);
ctx.addFailureAt(node.getStart(), node.getWidth(), msg);
}
return ts.forEachChild(node, cb);
}

return ts.forEachChild(ctx.sourceFile, cb);
}

0 comments on commit f1707e7

Please sign in to comment.