UNPKG

1.31 kBPlain TextView Raw
1import * as Lint from "tslint";
2import * as ts from "typescript";
3
4import { GeneralRuleUtils } from "./utils/GeneralRuleUtils";
5
6const RULE_ID = "tsf-folders-disabled-test";
7
8export class Rule extends Lint.Rules.AbstractRule {
9 apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
10 if (!GeneralRuleUtils.isInTestFile(sourceFile.fileName)) {
11 return [];
12 }
13
14 const walker = new StatementsWalker(sourceFile, this.getOptions());
15 this.applyWithWalker(walker);
16
17 return walker.getFailures();
18 }
19}
20
21class StatementsWalker extends Lint.RuleWalker {
22 visitCallExpression(node: ts.CallExpression) {
23 const text = node.getText();
24
25 if (text.startsWith("describe.only") || text.startsWith("it.only")) {
26 this.addFailureAtNode(
27 node.getFirstToken(),
28 GeneralRuleUtils.buildFailureString("do not enable only some tests", RULE_ID)
29 );
30 }
31
32 if (text.startsWith("describe.skip") || text.startsWith("it.skip")) {
33 this.addFailureAtNode(
34 node.getFirstToken(),
35 GeneralRuleUtils.buildFailureString("do not disable tests", RULE_ID)
36 );
37 }
38
39 super.visitCallExpression(node);
40 }
41}