From 5aeeff66422f7398ec8a2e210e309b57f5cd844c Mon Sep 17 00:00:00 2001 From: Jesse Ostrander Date: Mon, 22 Aug 2016 17:44:50 -0400 Subject: [PATCH] Update: Throw error if whitespace found in plugin name (fixes #6854) --- lib/config/plugins.js | 10 ++++++++++ messages/whitespace-found.txt | 3 +++ tests/lib/config/plugins.js | 6 ++++++ 3 files changed, 19 insertions(+) create mode 100644 messages/whitespace-found.txt diff --git a/lib/config/plugins.js b/lib/config/plugins.js index 08695f36ab78..7fcc035a74a6 100644 --- a/lib/config/plugins.js +++ b/lib/config/plugins.js @@ -108,6 +108,16 @@ module.exports = { pluginNameWithoutPrefix = removePrefix(pluginNameWithoutNamespace); let plugin = null; + if (pluginName.indexOf(" ") >= 0) { + const whitespaceError = new Error("Whitespace found in plugin name eslint-plugin-" + pluginNameWithoutPrefix); + + whitespaceError.messageTemplate = "whitespace-found"; + whitespaceError.messageData = { + pluginName: pluginNameWithoutPrefix + }; + throw whitespaceError; + } + if (!plugins[pluginNameWithoutPrefix]) { try { plugin = require(pluginNamespace + PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix); diff --git a/messages/whitespace-found.txt b/messages/whitespace-found.txt new file mode 100644 index 000000000000..7746f3533708 --- /dev/null +++ b/messages/whitespace-found.txt @@ -0,0 +1,3 @@ +ESLint couldn't find the plugin "eslint-plugin-<%- pluginName %>". It looks like there is whitespace in the plugin name. + +If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team. diff --git a/tests/lib/config/plugins.js b/tests/lib/config/plugins.js index 31d6be54fdb2..338008876317 100644 --- a/tests/lib/config/plugins.js +++ b/tests/lib/config/plugins.js @@ -82,6 +82,12 @@ describe("Plugins", function() { assert.deepEqual(Rules.get("example/qux"), plugin.rules.qux); }); + it("should throw an error when a plugin has whitespace", function() { + assert.throws(function() { + StubbedPlugins.load("whitespace "); + }, /Whitespace found in plugin name/); + }); + it("should throw an error when a plugin doesn't exist", function() { assert.throws(function() { StubbedPlugins.load("nonexistentplugin");