gplint
Version:
A Gherkin linter/validator written in Javascript.
43 lines • 1.35 kB
JavaScript
import * as gherkinUtils from './utils/gherkin.js';
import { featureSpread } from './utils/gherkin.js';
export const name = 'use-and';
export function run({ feature }) {
if (!feature) {
return [];
}
const errors = [];
featureSpread(feature).children.forEach(child => {
const node = child.background ?? child.scenario;
let previousKeyword = undefined;
node.steps.forEach(step => {
const keyword = gherkinUtils.getLanguageInsensitiveKeyword(step, feature.language);
if (keyword === 'and') {
return;
}
if (keyword === previousKeyword) {
errors.push(createError(step));
}
previousKeyword = keyword;
});
});
return errors;
}
function createError(step) {
return {
message: `Step "${step.keyword}${step.text}" should use And instead of ${step.keyword}`,
rule: name,
line: step.location.line,
column: step.location.column,
};
}
export const documentation = {
description: 'Disallows repeated step names requiring use of `And` instead.',
examples: [{
title: 'Example',
description: 'Enable rule',
config: {
[name]: 'error',
}
}],
};
//# sourceMappingURL=use-and.js.map