UNPKG

tslint-to-eslint-config

Version:

Converts your TSLint configuration to the closest reasonable ESLint equivalent.

57 lines (56 loc) 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertEditorConfigs = void 0; const types_1 = require("../../types"); const utils_1 = require("../../utils"); /** * @see /docs/Editors.md for documentation. */ const convertEditorConfigs = async (dependencies, settings) => { const results = { failed: new Map(), successes: new Map(), }; // 1. Requested `--editor` paths are deduplicated into the list of file paths to convert. const requestedPaths = (0, utils_1.uniqueFromSources)(settings.editor); await Promise.all( requestedPaths.map(async (requestedPath) => { // 2. Each path is mapped, if possible, to its editor's converter function. const descriptor = dependencies.editorConfigDescriptors.find(([defaultPath]) => defaultPathMatches(defaultPath, requestedPath), ); if (!descriptor) { results.failed.set( requestedPath, new Error(`Unknown editor config path requested: '${requestedPath}'.`), ); return; } // 3. Results from calling `convertEditorConfig` on that file and configuration are stored. const result = await dependencies.convertEditorConfig( descriptor[1], requestedPath, settings, ); if (result instanceof Error) { results.failed.set(requestedPath, result); } else { results.successes.set(requestedPath, result); } }), ); // 4. Results of converting are reported to the console and back to the calling code. dependencies.reportEditorConfigConversionResults(results); return results.failed.size === 0 ? { status: types_1.ResultStatus.Succeeded, } : { errors: Array.from(results.failed.values()), status: types_1.ResultStatus.Failed, }; }; exports.convertEditorConfigs = convertEditorConfigs; const defaultPathMatches = (defaultPath, requestedPath) => requestedPath.replace(/\W+/g, "").endsWith(defaultPath.replace(/\W+/g, "")); //# sourceMappingURL=convertEditorConfigs.js.map