gherkin-lint-ts
Version:
Gherkin features linter written in Typescript
69 lines • 2.89 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 gherkinUtils = __importStar(require("./utils/gherkin"));
const chalk_1 = __importDefault(require("chalk"));
const _ = require("lodash");
exports.name = "required-tags";
exports.availableConfigs = {
tags: [],
ignoreUntagged: true,
};
function run(feature, unused, config) {
var _a;
if (!feature) {
return [];
}
const mergedConfig = _.merge({}, exports.availableConfigs, config);
const errors = [];
(_a = feature.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
var _a, _b;
if (child.scenario) {
const type = gherkinUtils.getNodeType(child.scenario, feature.language);
const line = ((_a = child.scenario.location) === null || _a === void 0 ? void 0 : _a.line) || 0;
const scenarioTags = ((_b = child.scenario) === null || _b === void 0 ? void 0 : _b.tags) || [];
// Check each Scenario for the required tags
mergedConfig.tags.forEach(tag => {
if (!checkTagExists(tag, mergedConfig.ignoreUntagged, scenarioTags)) {
errors.push(createError(tag, type, line));
}
});
}
});
return errors;
}
exports.run = run;
function checkTagExists(requiredTag, ignoreUntagged, scenarioTags) {
return (ignoreUntagged && scenarioTags.length === 0)
|| scenarioTags.some((tagObj) => RegExp(requiredTag).test(tagObj.name || ""));
}
function createError(requiredTag, scenarioType, scenarioLine) {
return {
message: `No tag found matching ${chalk_1.default.yellow(requiredTag)} for ${chalk_1.default.cyan(scenarioType)}`,
rule: exports.name,
line: scenarioLine,
};
}
//# sourceMappingURL=required-tags.js.map