gherkin-lint-ts
Version:
Gherkin features linter written in Typescript
82 lines • 3.24 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.availableConfigs = exports.name = void 0;
const gherkinUtils = __importStar(require("./utils/gherkin"));
const chalk_1 = __importDefault(require("chalk"));
const _ = require("lodash");
exports.name = "scenario-size";
exports.availableConfigs = {
"steps-length": {
"Rule": 15,
"Background": 15,
"Scenario": 15,
},
};
function run(feature, unused, configuration) {
var _a;
if (!feature) {
return [];
}
if (_.isEmpty(configuration)) {
configuration = exports.availableConfigs;
}
const errors = [];
(_a = feature.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
var _a;
const node = child.rule || child.background || child.scenario;
if (node) {
const nodeType = gherkinUtils.getNodeType(node, feature.language);
const configKey = child.rule ? "Rule" : child.background ? "Background" : "Scenario";
const maxSize = configuration["steps-length"][configKey];
if (maxSize) {
if (child.rule) {
(_a = child.rule.children) === null || _a === void 0 ? void 0 : _a.forEach(ruleChild => {
const ruleNode = ruleChild.background || ruleChild.scenario;
if (ruleNode) {
checkSteps(ruleNode, maxSize, errors, nodeType);
}
});
}
else {
checkSteps(node, maxSize, errors, nodeType);
}
}
}
});
return errors;
}
exports.run = run;
function checkSteps(node, maxSize, errors, nodeType) {
var _a, _b;
let length = ((_a = node.steps) === null || _a === void 0 ? void 0 : _a.length) || -1;
if (length > maxSize) {
errors.push({
message: `Element ${chalk_1.default.cyan(nodeType)} too long: actual ${length}, expected ${maxSize}`,
rule: exports.name,
line: ((_b = node.location) === null || _b === void 0 ? void 0 : _b.line) || 0,
});
}
}
//# sourceMappingURL=scenario-size.js.map