gplint
Version:
A Gherkin linter/validator written in Javascript.
54 lines • 2.11 kB
JavaScript
import _ from 'lodash';
import * as gherkinUtils from './utils/gherkin.js';
export const name = 'no-superfluous-tags';
export function run({ feature }) {
if (!feature) {
return [];
}
const errors = [];
checkSuperfluousContainer(feature, feature.language, errors);
return errors;
}
function checkSuperfluousContainer(container, lang, errors, parentContainer) {
const containers = parentContainer ? [container, parentContainer] : [container];
container.children.forEach(child => {
if (child.scenario) {
checkTags(child.scenario, containers, lang, errors);
if (child.scenario.keyword === 'Scenario Outline') {
child.scenario.examples.forEach(example => {
checkTags(example, [...containers, child.scenario], lang, errors);
});
}
}
else if (child.rule) {
checkTags(child.rule, containers, lang, errors);
checkSuperfluousContainer(child.rule, lang, errors, container);
}
});
}
function checkTags(child, parents, language, errors) {
for (const parent of parents) {
const superfluousTags = _.intersectionBy(child.tags, parent.tags, 'name');
const childType = gherkinUtils.getNodeType(child, language);
const parentType = gherkinUtils.getNodeType(parent, language);
superfluousTags.forEach(tag => {
errors.push({
message: `Tag duplication between ${childType} and its corresponding ${parentType}: ${tag.name}`,
rule: name,
line: tag.location.line,
column: tag.location.column,
});
});
}
}
export const documentation = {
description: 'Disallows tags present on a Node, its parents (E.g. Same tags in a Scenario and/or Example, and also on the Feature or Rule that contains it.',
examples: [{
title: 'Example',
description: 'Enable rule',
config: {
[name]: 'error',
}
}],
};
//# sourceMappingURL=no-superfluous-tags.js.map