All files noClassRule.ts

100% Statements 17/17
100% Branches 5/5
100% Functions 4/4
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x 1x   1x 1x   1x 1x 1x   1x   1x   1x   9x 1x   9x     1x  
import * as ts from "typescript";
import * as Lint from "tslint";
 
export class Rule extends Lint.Rules.AbstractRule {
  public static FAILURE_STRING = "Unexpected class, use functions not classes.";
 
  public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
    const noClassKeywordWalker = new NoClassWalker(sourceFile, this.getOptions());
    return this.applyWithWalker(noClassKeywordWalker);
  }
}
 
class NoClassWalker extends Lint.RuleWalker {
 
  public visitNode(node: ts.Node): void {
 
    if (node && node.kind === ts.SyntaxKind.ClassKeyword || node.kind === ts.SyntaxKind.ClassDeclaration) {
      this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
    }
    super.visitNode(node);
  }
 
}