UNPKG

gherkin-lint-ts

Version:

Gherkin features linter written in Typescript

76 lines 3.12 kB
"use strict"; 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 = "no-restricted-tags"; exports.availableConfigs = { "tags": [], "patterns": [], }; function run(feature, unused, configuration) { var _a; if (!feature) { return []; } const forbiddenTags = configuration.tags; const forbiddenPatterns = getForbiddenPatterns(configuration); const language = feature.language; const errors = []; checkTags(feature, language, forbiddenTags, forbiddenPatterns, errors); (_a = feature.children) === null || _a === void 0 ? void 0 : _a.forEach(child => { var _a; // backgrounds don't have tags if (child.scenario) { checkTags(child.scenario, language, forbiddenTags, forbiddenPatterns, errors); (_a = child.scenario.examples) === null || _a === void 0 ? void 0 : _a.forEach(example => { checkTags(example, language, forbiddenTags, forbiddenPatterns, errors); }); } }); return errors; } exports.run = run; function getForbiddenPatterns(configuration) { return (configuration.patterns || []).map((pattern) => new RegExp(pattern)); } function checkTags(node, language, forbiddenTags, forbiddenPatterns, errors) { const nodeType = gherkinUtils.getNodeType(node, language); node.tags.forEach(tag => { if (isForbidden(tag, forbiddenTags, forbiddenPatterns)) { errors.push({ message: `Forbidden tag ${chalk_1.default.yellow(tag.name)} on ${chalk_1.default.cyan(nodeType)}`, rule: exports.name, line: tag.location.line, }); } }); } function isForbidden(tag, forbiddenTags, forbiddenPatterns) { return _.includes(forbiddenTags, tag.name) || forbiddenPatterns.some((pattern) => pattern.test(tag.name)); } //# sourceMappingURL=no-restricted-tags.js.map