UNPKG

gherkin-lint-ts

Version:

Gherkin features linter written in Typescript

56 lines 2.47 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getConfiguration = exports.defaultFormat = exports.defaultConfigFileName = void 0; const logger = __importStar(require("../utils/logger")); const config_verifier_1 = require("./config-verifier"); const fs = __importStar(require("fs")); const stripJsonComments = require("strip-json-comments"); exports.defaultConfigFileName = ".gherkin-lintrc.json"; exports.defaultFormat = "stylish"; function getConfiguration(configPath, additionalRulesDirs) { if (configPath) { if (!fs.existsSync(configPath)) { logger.boldError(`Could not find specified config file "${configPath}"`); return process.exit(1); } } else { if (!fs.existsSync(exports.defaultConfigFileName)) { logger.boldError(`Could not find default config file "${exports.defaultConfigFileName}" in the working directory. To use a custom name/path provide the config file using the "-c" arg.`); return process.exit(1); } configPath = exports.defaultConfigFileName; } const config = JSON.parse(stripJsonComments(fs.readFileSync(configPath, { encoding: "utf-8" }))); const errors = config_verifier_1.verifyConfigurationFile(config, additionalRulesDirs); if (errors.length > 0) { logger.boldError("Error(s) in configuration file:"); errors.forEach(error => { logger.error(`- ${error}`); }); process.exit(1); } return config; } exports.getConfiguration = getConfiguration; //# sourceMappingURL=config-parser.js.map