UNPKG

gplint

Version:

A Gherkin linter/validator written in Javascript.

54 lines 1.62 kB
import _ from 'lodash'; import { featureSpread } from './utils/gherkin.js'; export const name = 'no-duplicate-tags'; export function run({ feature }) { if (!feature) { return []; } const errors = []; verifyTags(feature, errors); const { children, rules } = featureSpread(feature); rules.forEach(rule => { verifyTags(rule, errors); }); children.forEach(child => { if (child.scenario) { verifyTags(child.scenario, errors); child.scenario.examples.forEach(example => { verifyTags(example, errors); }); } }); return errors; } function verifyTags(node, errors) { const failedTagNames = []; const uniqueTagNames = []; node.tags.forEach(tag => { if (!_.includes(failedTagNames, tag.name)) { if (_.includes(uniqueTagNames, tag.name)) { errors.push({ message: `Duplicate tags are not allowed: ${tag.name}`, rule: name, line: tag.location.line, column: tag.location.column, }); failedTagNames.push(tag.name); } else { uniqueTagNames.push(tag.name); } } }); } export const documentation = { description: 'Disallows duplicate tags on the same Feature or Scenario.', examples: [{ title: 'Example', description: 'Enable rule', config: { [name]: 'error', } }], }; //# sourceMappingURL=no-duplicate-tags.js.map