1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var ts = require("typescript");
|
14 | var Lint = require("tslint");
|
15 | var ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
|
16 | var MochaUtils_1 = require("./utils/MochaUtils");
|
17 | var Rule = (function (_super) {
|
18 | __extends(Rule, _super);
|
19 | function Rule() {
|
20 | return _super !== null && _super.apply(this, arguments) || this;
|
21 | }
|
22 | Rule.prototype.apply = function (sourceFile) {
|
23 | return this.applyWithWalker(new MochaAvoidOnlyRuleWalker(sourceFile, this.getOptions()));
|
24 | };
|
25 | Rule.metadata = {
|
26 | ruleName: 'mocha-avoid-only',
|
27 | type: 'maintainability',
|
28 | description: 'Do not invoke Mocha\'s describe.only, it.only or context.only functions.',
|
29 | options: null,
|
30 | optionsDescription: '',
|
31 | typescriptOnly: true,
|
32 | issueClass: 'Non-SDL',
|
33 | issueType: 'Error',
|
34 | severity: 'Critical',
|
35 | level: 'Opportunity for Excellence',
|
36 | group: 'Correctness'
|
37 | };
|
38 | Rule.FAILURE_STRING_IT = 'Do not commit Mocha it.only function call';
|
39 | Rule.FAILURE_STRING_SPECIFY = 'Do not commit Mocha specify.only function call';
|
40 | Rule.FAILURE_STRING_DESCRIBE = 'Do not commit Mocha describe.only function call';
|
41 | Rule.FAILURE_STRING_CONTEXT = 'Do not commit Mocha context.only function call';
|
42 | return Rule;
|
43 | }(Lint.Rules.AbstractRule));
|
44 | exports.Rule = Rule;
|
45 | var MochaAvoidOnlyRuleWalker = (function (_super) {
|
46 | __extends(MochaAvoidOnlyRuleWalker, _super);
|
47 | function MochaAvoidOnlyRuleWalker() {
|
48 | return _super !== null && _super.apply(this, arguments) || this;
|
49 | }
|
50 | MochaAvoidOnlyRuleWalker.prototype.visitSourceFile = function (node) {
|
51 | if (MochaUtils_1.MochaUtils.isMochaTest(node)) {
|
52 | _super.prototype.visitSourceFile.call(this, node);
|
53 | }
|
54 | };
|
55 | MochaAvoidOnlyRuleWalker.prototype.visitCallExpression = function (node) {
|
56 | if (node.expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
|
57 | if (node.arguments.length === 2) {
|
58 | if (node.arguments[0].kind === ts.SyntaxKind.StringLiteral) {
|
59 | if (node.arguments[1].kind === ts.SyntaxKind.FunctionExpression
|
60 | || node.arguments[1].kind === ts.SyntaxKind.ArrowFunction) {
|
61 | if (node.expression.getText() === 'it.only') {
|
62 | this.addFailureAt(node.getStart(), node.expression.getText().length, Rule.FAILURE_STRING_IT);
|
63 | }
|
64 | else if (node.expression.getText() === 'specify.only') {
|
65 | this.addFailureAt(node.getStart(), node.expression.getText().length, Rule.FAILURE_STRING_SPECIFY);
|
66 | }
|
67 | else if (node.expression.getText() === 'describe.only') {
|
68 | this.addFailureAt(node.getStart(), node.expression.getText().length, Rule.FAILURE_STRING_DESCRIBE);
|
69 | }
|
70 | else if (node.expression.getText() === 'context.only') {
|
71 | this.addFailureAt(node.getStart(), node.expression.getText().length, Rule.FAILURE_STRING_CONTEXT);
|
72 | }
|
73 | }
|
74 | }
|
75 | }
|
76 | }
|
77 | _super.prototype.visitCallExpression.call(this, node);
|
78 | };
|
79 | return MochaAvoidOnlyRuleWalker;
|
80 | }(ErrorTolerantWalker_1.ErrorTolerantWalker));
|
81 |
|
\ | No newline at end of file |