UNPKG

gherkin-lint-ts

Version:

Gherkin features linter written in Typescript

52 lines 1.85 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-duplicate-tags"; function run(feature) { var _a; if (!feature) { return []; } const errors = []; verifyTags(feature, errors); (_a = feature.children) === null || _a === void 0 ? void 0 : _a.forEach(child => { var _a; if (child.scenario) { verifyTags(child.scenario, errors); (_a = child.scenario.examples) === null || _a === void 0 ? void 0 : _a.forEach(example => { verifyTags(example, errors); }); } }); return errors; } exports.run = run; function verifyTags(node, errors) { var _a; const failedTagNames = []; const uniqueTagNames = []; (_a = node === null || node === void 0 ? void 0 : node.tags) === null || _a === void 0 ? void 0 : _a.forEach(tag => { var _a; if (tag.name) { if (!_.includes(failedTagNames, tag.name)) { if (_.includes(uniqueTagNames, tag.name)) { errors.push({ message: `Duplicate tags are not allowed: ${chalk_1.default.yellow(tag.name)}`, rule: exports.name, line: ((_a = tag.location) === null || _a === void 0 ? void 0 : _a.line) || 0, }); failedTagNames.push(tag.name); } else { uniqueTagNames.push(tag.name); } } } }); } //# sourceMappingURL=no-duplicate-tags.js.map