UNPKG

gherkin-lint-ts

Version:

Gherkin features linter written in Typescript

58 lines 2.1 kB
"use strict"; 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 = "allowed-tags"; exports.availableConfigs = { "tags": [], "patterns": [], }; function run(feature, unused, configuration) { var _a; if (!feature) { return []; } const errors = []; const allowedTags = configuration.tags; const allowedPatterns = getAllowedPatterns(configuration); checkTags(feature, allowedTags, allowedPatterns, errors); (_a = feature.children) === null || _a === void 0 ? void 0 : _a.forEach(child => { if (child.scenario) { checkTags(child.scenario, allowedTags, allowedPatterns, errors); if (child.scenario.examples) { child.scenario.examples.forEach(example => { checkTags(example, allowedTags, allowedPatterns, errors); }); } } }); return errors; } exports.run = run; function getAllowedPatterns(configuration) { return (configuration.patterns || []).map((pattern) => new RegExp(pattern)); } function checkTags(node, allowedTags, allowedPatterns, errors) { return (node.tags || []) .filter(tag => !isAllowed(tag, allowedTags, allowedPatterns)) .forEach(tag => { errors.push(createError(node, tag)); }); } function isAllowed(tag, allowedTags, allowedPatterns) { return _.includes(allowedTags, tag.name) || allowedPatterns.some((pattern) => pattern.test(tag.name)); } function createError(node, tag) { var _a; return { message: `Not allowed tag ${chalk_1.default.yellow(tag.name)} on ${chalk_1.default.cyan(node.keyword)}`, rule: exports.name, line: ((_a = tag.location) === null || _a === void 0 ? void 0 : _a.line) || 0, }; } //# sourceMappingURL=allowed-tags.js.map