1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | __.prototype = b.prototype;
|
5 | d.prototype = new __();
|
6 | };
|
7 | var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
|
8 | var SyntaxKind = require('./utils/SyntaxKind');
|
9 | var Rule = (function (_super) {
|
10 | __extends(Rule, _super);
|
11 | function Rule() {
|
12 | _super.apply(this, arguments);
|
13 | }
|
14 | Rule.prototype.apply = function (sourceFile) {
|
15 | return this.applyWithWalker(new MochaAvoidOnlyRuleWalker(sourceFile, this.getOptions()));
|
16 | };
|
17 | Rule.FAILURE_STRING_IT = 'Do not commit Mocha it.only function call';
|
18 | Rule.FAILURE_STRING_DESCRIBE = 'Do not commit Mocha describe.only function call';
|
19 | return Rule;
|
20 | })(Lint.Rules.AbstractRule);
|
21 | exports.Rule = Rule;
|
22 | var MochaAvoidOnlyRuleWalker = (function (_super) {
|
23 | __extends(MochaAvoidOnlyRuleWalker, _super);
|
24 | function MochaAvoidOnlyRuleWalker() {
|
25 | _super.apply(this, arguments);
|
26 | }
|
27 | MochaAvoidOnlyRuleWalker.prototype.visitCallExpression = function (node) {
|
28 | if (node.expression.kind === SyntaxKind.current().PropertyAccessExpression) {
|
29 | if (node.arguments.length === 2) {
|
30 | if (node.arguments[0].kind === SyntaxKind.current().StringLiteral) {
|
31 | if (node.arguments[1].kind === SyntaxKind.current().FunctionExpression
|
32 | || node.arguments[1].kind === SyntaxKind.current().ArrowFunction) {
|
33 | if (node.expression.getText() === 'it.only') {
|
34 | this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING_IT));
|
35 | }
|
36 | else if (node.expression.getText() === 'describe.only') {
|
37 | this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING_DESCRIBE));
|
38 | }
|
39 | }
|
40 | }
|
41 | }
|
42 | }
|
43 | _super.prototype.visitCallExpression.call(this, node);
|
44 | };
|
45 | return MochaAvoidOnlyRuleWalker;
|
46 | })(ErrorTolerantWalker);
|
47 |
|
\ | No newline at end of file |