Skip to content

Commit

Permalink
convert no-with-statement rule to use a walk function (microsoft#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
drexler authored and apawast committed Feb 26, 2019
1 parent 276999c commit fa6a398
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/noWithStatementRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING: string = 'Forbidden with statement';

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

class NoWithStatementWalker extends Lint.RuleWalker {
protected visitNode(node: ts.Node): void {
function walk(ctx: Lint.WalkContext<void>) {
function cb(node: ts.Node): void {
if (node.kind === ts.SyntaxKind.WithStatement) {
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
ctx.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
}
super.visitNode(node);
}

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

0 comments on commit fa6a398

Please sign in to comment.