UNPKG

gherkin-lint-ts

Version:

Gherkin features linter written in Typescript

70 lines 2.73 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.name = void 0; const gherkinUtils = __importStar(require("./utils/gherkin")); const chalk_1 = __importDefault(require("chalk")); exports.name = "use-and"; function run(feature) { var _a; if (!feature) { return []; } const errors = []; (_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.map(it => it.background || it.scenario).forEach(it => checkKeyword(it, feature, errors)); } else { const node = child.background || child.scenario; checkKeyword(node, feature, errors); } }); return errors; } exports.run = run; function checkKeyword(node, feature, errors) { var _a; let previousKeyword = undefined; (_a = node === null || node === void 0 ? void 0 : node.steps) === null || _a === void 0 ? void 0 : _a.forEach(step => { const keyword = gherkinUtils.getLanguageInsensitiveKeyword(step, feature.language); if (keyword === "and") { return; } if (keyword === previousKeyword) { errors.push(createError(step)); } previousKeyword = keyword; }); } function createError(step) { var _a; return { message: `Step "${chalk_1.default.yellow(`${step.keyword}${step.text}`)}" should use And instead of ${chalk_1.default.cyan(step.keyword)}`, rule: exports.name, line: ((_a = step.location) === null || _a === void 0 ? void 0 : _a.line) || 0, }; } //# sourceMappingURL=use-and.js.map