gplint
Version:
A Gherkin linter/validator written in Javascript.
40 lines • 1.21 kB
JavaScript
export const name = 'no-background-only-scenario';
export function run({ feature }) {
if (!feature) {
return [];
}
const errors = [];
function checkScenariosContainer(container) {
container.children.forEach(child => {
if (child.background) {
if (container.children.filter(c => c.scenario).length < 2) {
errors.push(createError(child.background));
}
}
else if (child.rule) {
checkScenariosContainer(child.rule);
}
});
}
checkScenariosContainer(feature);
return errors;
}
function createError(background) {
return {
message: 'Backgrounds are not allowed when there is just one scenario.',
rule: name,
line: background.location.line,
column: background.location.column,
};
}
export const documentation = {
description: 'Disallows background when there is just one scenario.',
examples: [{
title: 'Example',
description: 'Enable rule',
config: {
[name]: 'error',
}
}],
};
//# sourceMappingURL=no-background-only-scenario.js.map