UNPKG

gherkin-lint-ts

Version:

Gherkin features linter written in Typescript

43 lines 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = exports.name = void 0; const _ = require("lodash"); exports.name = "max-scenarios-per-file"; const defaultConfig = { "maxScenarios": 10, "countOutlineExamples": true, }; function run(feature, unused, config) { var _a, _b; if (!feature) { return []; } const errors = []; const mergedConfiguration = _.merge({}, defaultConfig, config); const maxScenarios = mergedConfiguration.maxScenarios; let count = ((_a = feature.children) === null || _a === void 0 ? void 0 : _a.length) || 0; (_b = feature.children) === null || _b === void 0 ? void 0 : _b.forEach(child => { var _a, _b; if (child.background) { count = count - 1; } else if (((_b = (_a = child.scenario) === null || _a === void 0 ? void 0 : _a.examples) === null || _b === void 0 ? void 0 : _b.length) && mergedConfiguration.countOutlineExamples) { count = count - 1; child.scenario.examples.forEach(example => { if (example.tableBody) { count = count + example.tableBody.length; } }); } }); if (count > maxScenarios) { errors.push({ message: `Number of scenarios exceeds maximum: ${count}/${maxScenarios}`, rule: exports.name, line: 0, }); } return errors; } exports.run = run; //# sourceMappingURL=max-scenarios-per-file.js.map