UNPKG

@elsikora/eslint-config

Version:

ESLint configuration vision of ElsiKora

30 lines (27 loc) 1.12 kB
'use strict'; /** * Extracts a sub-plugin from a plugin object. * @param {ESLint.Plugin} plugin - The plugin object to extract the sub-plugin from * @param {string} subPluginName - The name of the sub-plugin to extract * @param {string} skipPluginName - The name of the plugin to skip when extracting the sub-plugin * @returns {ESLint.Plugin} The extracted sub-plugin object */ function extractSubPlugin(plugin, subPluginName, skipPluginName) { const newPlugin = { ...plugin }; const newRules = {}; if (newPlugin.rules) { for (const key of Object.keys(newPlugin.rules)) { let newKey = key; if (skipPluginName) newKey = newKey.replace(`${skipPluginName}/`, ""); if (newKey.split("/").length > 1 && newKey.includes(subPluginName)) { // @ts-ignore newRules[newKey.split("/").slice(1).join("/")] = newPlugin.rules[key]; } } newPlugin.rules = newRules; } return newPlugin; } exports.extractSubPlugin = extractSubPlugin; //# sourceMappingURL=extract-sub-plugin.utility.js.map