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