UNPKG

tslint-to-eslint-config

Version:

Converts your TSLint configuration to the closest reasonable ESLint equivalent.

48 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findTSLintConfiguration = void 0; const utils_1 = require("../utils"); const findRawConfiguration_1 = require("./findRawConfiguration"); const findReportedConfiguration_1 = require("./findReportedConfiguration"); const knownErrors = [ [ "command not found", () => new Error("The 'tslint' command was not found. Either install it globally or add it as a devDependency of this repository."), ], [ "unknown option `--print-config", () => new Error("TSLint v5.18 required. Please update your version."), ], [ "Could not find configuration path.", (filePath) => new Error(`Could not find your TSLint configuration file at '${filePath}'. Try providing a different --tslint path.`), ], ]; const findTSLintConfiguration = async (dependencies, config) => { var _a, _b; const filePath = config !== null && config !== void 0 ? config : "./tslint.json"; const [rawConfiguration, reportedConfiguration] = await Promise.all([ (0, findRawConfiguration_1.findRawConfiguration)(dependencies.importer, filePath), (0, findReportedConfiguration_1.findReportedConfiguration)(dependencies.exec, "tslint --print-config", filePath), ]); if (reportedConfiguration instanceof Error) { return ((_b = (_a = knownErrors.find(([knownError]) => reportedConfiguration.message.includes(knownError))) === null || _a === void 0 ? void 0 : _a[1](filePath)) !== null && _b !== void 0 ? _b : reportedConfiguration); } if (rawConfiguration instanceof Error) { return rawConfiguration; } const extensions = (0, utils_1.uniqueFromSources)(rawConfiguration.extends, reportedConfiguration.extends); const rules = { ...rawConfiguration.rules, ...reportedConfiguration.rules, }; return { full: { ...(extensions.length !== 0 && { extends: extensions }), rules, }, raw: rawConfiguration, }; }; exports.findTSLintConfiguration = findTSLintConfiguration; //# sourceMappingURL=findTSLintConfiguration.js.map