diff options
Diffstat (limited to 'tools/eslint/lib/config/plugins.js')
-rw-r--r-- | tools/eslint/lib/config/plugins.js | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/tools/eslint/lib/config/plugins.js b/tools/eslint/lib/config/plugins.js index 9b813f3c14..73c8a7daf2 100644 --- a/tools/eslint/lib/config/plugins.js +++ b/tools/eslint/lib/config/plugins.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const Environments = require("./environments"), - rules = require("../rules"); + Rules = require("../rules"); const debug = require("debug")("eslint:plugins"); @@ -55,9 +55,9 @@ function removeNamespace(pluginName) { module.exports = { - removePrefix: removePrefix, - getNamespace: getNamespace, - removeNamespace: removeNamespace, + removePrefix, + getNamespace, + removeNamespace, /** * Defines a plugin with a given name rather than loading from disk. @@ -65,18 +65,22 @@ module.exports = { * @param {Object} plugin The plugin object. * @returns {void} */ - define: function(pluginName, plugin) { - const pluginNameWithoutNamespace = removeNamespace(pluginName), - pluginNameWithoutPrefix = removePrefix(pluginNameWithoutNamespace); - - plugins[pluginNameWithoutPrefix] = plugin; + define(pluginName, plugin) { + const pluginNamespace = getNamespace(pluginName), + pluginNameWithoutNamespace = removeNamespace(pluginName), + pluginNameWithoutPrefix = removePrefix(pluginNameWithoutNamespace), + shortName = pluginNamespace + pluginNameWithoutPrefix; // load up environments and rules - Environments.importPlugin(plugin, pluginNameWithoutPrefix); + plugins[shortName] = plugin; + Environments.importPlugin(plugin, shortName); + Rules.importPlugin(plugin, shortName); - if (plugin.rules) { - rules.import(plugin.rules, pluginNameWithoutPrefix); - } + // load up environments and rules for the name that '@scope/' was omitted + // 3 lines below will be removed by 4.0.0 + plugins[pluginNameWithoutPrefix] = plugin; + Environments.importPlugin(plugin, pluginNameWithoutPrefix); + Rules.importPlugin(plugin, pluginNameWithoutPrefix); }, /** @@ -84,7 +88,7 @@ module.exports = { * @param {string} pluginName The name of the plugin to retrieve. * @returns {Object} The plugin or null if not loaded. */ - get: function(pluginName) { + get(pluginName) { return plugins[pluginName] || null; }, @@ -92,7 +96,7 @@ module.exports = { * Returns all plugins that are loaded. * @returns {Object} The plugins cache. */ - getAll: function() { + getAll() { return plugins; }, @@ -102,21 +106,23 @@ module.exports = { * @returns {void} * @throws {Error} If the plugin cannot be loaded. */ - load: function(pluginName) { + load(pluginName) { const pluginNamespace = getNamespace(pluginName), pluginNameWithoutNamespace = removeNamespace(pluginName), - pluginNameWithoutPrefix = removePrefix(pluginNameWithoutNamespace); + pluginNameWithoutPrefix = removePrefix(pluginNameWithoutNamespace), + shortName = pluginNamespace + pluginNameWithoutPrefix, + longName = pluginNamespace + PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix; let plugin = null; - if (!plugins[pluginNameWithoutPrefix]) { + if (!plugins[shortName]) { try { - plugin = require(pluginNamespace + PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix); + plugin = require(longName); } catch (err) { - debug("Failed to load plugin eslint-plugin-" + pluginNameWithoutPrefix + ". Proceeding without it."); + debug("Failed to load plugin " + longName + "."); err.message = "Failed to load plugin " + pluginName + ": " + err.message; err.messageTemplate = "plugin-missing"; err.messageData = { - pluginName: pluginNameWithoutPrefix + pluginName: longName }; throw err; } @@ -131,7 +137,7 @@ module.exports = { * @returns {void} * @throws {Error} If a plugin cannot be loaded. */ - loadAll: function(pluginNames) { + loadAll(pluginNames) { pluginNames.forEach(this.load, this); }, @@ -139,7 +145,7 @@ module.exports = { * Resets plugin information. Use for tests only. * @returns {void} */ - testReset: function() { + testReset() { plugins = Object.create(null); } }; |