gherkin-lint-ts
Version:
Gherkin features linter written in Typescript
65 lines • 2.44 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"));
const _ = require("lodash");
exports.name = "name-length";
exports.availableConfigs = {
"Feature": 70,
"Rule": 70,
"Step": 70,
"Scenario": 70,
};
function run(feature, unused, configuration) {
var _a;
if (!feature) {
return [];
}
const errors = [];
const mergedConfiguration = _.merge(exports.availableConfigs, configuration);
// Check Feature name length
test(feature.name, feature.location, mergedConfiguration, "Feature", errors);
(_a = feature.children) === null || _a === void 0 ? void 0 : _a.forEach(child => {
var _a;
if (child.rule) {
test(child.rule.name, child.rule.location, mergedConfiguration, "Rule", errors);
(_a = child.rule.children) === null || _a === void 0 ? void 0 : _a.forEach(ruleChild => {
checkNode(ruleChild, mergedConfiguration, errors);
});
}
else {
checkNode(child, mergedConfiguration, errors);
}
});
return errors;
}
exports.run = run;
function checkNode(child, mergedConfiguration, errors) {
if (child.background) {
testSteps(child.background, mergedConfiguration, errors);
}
else if (child.scenario) {
test(child.scenario.name, child.scenario.location, mergedConfiguration, "Scenario", errors);
testSteps(child.scenario, mergedConfiguration, errors);
}
}
function test(nameString, location, configuration, type, errors) {
if (nameString && (nameString.length > configuration[type])) {
errors.push({
message: `${chalk_1.default.cyan(type)} name is too long. Length of ${nameString.length} is longer than the maximum allowed: ${configuration[type]}`,
rule: exports.name,
line: location.line,
});
}
}
function testSteps(node, mergedConfiguration, errors) {
var _a;
(_a = node.steps) === null || _a === void 0 ? void 0 : _a.forEach(step => {
// Check Step name length
test(step.text, step.location, mergedConfiguration, "Step", errors);
});
}
//# sourceMappingURL=name-length.js.map