gherkin-lint-ts
Version:
Gherkin features linter written in Typescript
69 lines • 2.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.availableConfigs = exports.name = void 0;
const chalk_1 = __importDefault(require("chalk"));
exports.name = "no-dupe-scenario-names";
exports.availableConfigs = [
"anywhere",
"in-feature",
];
let scenarios = [];
function run(feature, file, configuration) {
var _a;
if (!feature) {
return [];
}
const errors = [];
if (configuration === "in-feature") {
scenarios = [];
}
(_a = feature.children) === null || _a === void 0 ? void 0 : _a.forEach(child => {
var _a;
if (child.rule) {
(_a = child.rule.children) === null || _a === void 0 ? void 0 : _a.filter(it => it.scenario).forEach(ruleChild => checkScenario(ruleChild.scenario, file, errors));
}
if (child.scenario) {
checkScenario(child.scenario, file, errors);
}
});
return errors;
}
exports.run = run;
function checkScenario(scenario, file, errors) {
var _a, _b, _c;
if (scenario.name) {
if (scenario.name in scenarios) {
const dupes = getFileLinePairsAsStr(scenarios[scenario.name].locations);
scenarios[scenario.name].locations.push({
file: file.relativePath,
line: (_a = scenario.location) === null || _a === void 0 ? void 0 : _a.line,
});
errors.push({
message: `Scenario name is already used in: ${chalk_1.default.underline(dupes)}`,
rule: exports.name,
line: ((_b = scenario.location) === null || _b === void 0 ? void 0 : _b.line) || 0,
});
}
else {
scenarios[scenario.name] = {
locations: [
{
file: file.relativePath,
line: (_c = scenario.location) === null || _c === void 0 ? void 0 : _c.line,
},
],
};
}
}
}
function getFileLinePairsAsStr(objects) {
let strings = [];
objects.forEach(object => {
strings.push(`${object.file}:${object.line}`);
});
return strings.join(", ");
}
//# sourceMappingURL=no-dupe-scenario-names.js.map