UNPKG

gherkin-lint-ts

Version:

Gherkin features linter written in Typescript

54 lines 2.26 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = exports.name = void 0; const chalk_1 = __importDefault(require("chalk")); const _ = require("lodash"); exports.name = "no-homogenous-tags"; function run(feature) { var _a, _b; if (!feature) { return []; } const errors = []; // Tags that exist in every scenario and scenario outline // should be applied on a feature level const childrenTags = []; (_a = feature.children) === null || _a === void 0 ? void 0 : _a.forEach(child => { var _a, _b; if (child.scenario) { let scenario = child.scenario; childrenTags.push(getTagNames(scenario)); let exampleTags = []; (_a = scenario.examples) === null || _a === void 0 ? void 0 : _a.forEach(example => { exampleTags.push(getTagNames(example)); }); const homogenousExampleTags = _.intersection(...exampleTags); if (homogenousExampleTags.length) { errors.push({ message: `${"All Examples of a Scenario Outline have the same tag(s), " + "they should be defined on the Scenario Outline instead: "}${chalk_1.default.yellow(homogenousExampleTags.join(", "))}`, rule: exports.name, line: ((_b = scenario.location) === null || _b === void 0 ? void 0 : _b.line) || 0, }); } } }); const homogenousTags = _.intersection(...childrenTags); if (homogenousTags.length) { errors.push({ message: `${"All Scenarios on this Feature have the same tag(s), " + "they should be defined on the Feature instead: "}${chalk_1.default.yellow(homogenousTags.join(", "))}`, rule: exports.name, line: ((_b = feature.location) === null || _b === void 0 ? void 0 : _b.line) || 0, }); } return errors; } exports.run = run; function getTagNames(node) { return _.map(node.tags, tag => tag.name); } //# sourceMappingURL=no-homogenous-tags.js.map