UNPKG

gplint

Version:

A Gherkin linter/validator written in Javascript.

51 lines 1.63 kB
export const name = 'no-background-only-scenario'; export function run({ feature }) { if (!feature) { return []; } const errors = []; function checkScenariosContainer(container) { const hasBackground = container.children.some(child => child.background); const scenarioCount = container.children.reduce(countScenarios, 0); if (hasBackground && scenarioCount < 2) { const background = container.children.find(child => child.background)?.background; if (background) { errors.push(createError(background)); } } container.children .filter(child => child.rule) .forEach(child => checkScenariosContainer(child.rule)); } checkScenariosContainer(feature); return errors; } function countScenarios(count, child) { let inc = 0; if (child.scenario != null) { inc = 1; } else if (child.rule != null) { inc = child.rule.children.reduce(countScenarios, 0); } return count + inc; } 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