From be29599c6e12175c5a48e117526bd204bf82fda5 Mon Sep 17 00:00:00 2001 From: Jesse Ostrander Date: Sat, 3 Sep 2016 11:23:46 -0400 Subject: [PATCH] Update: Throw error if whitespace found in plugin name (fixes #6854) (#6960) --- lib/config/plugins.js | 10 ++++++++++ messages/whitespace-found.txt | 3 +++ tests/lib/config/plugins.js | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 messages/whitespace-found.txt diff --git a/lib/config/plugins.js b/lib/config/plugins.js index 73c8a7daf26..460dc89c8d9 100644 --- a/lib/config/plugins.js +++ b/lib/config/plugins.js @@ -114,6 +114,16 @@ module.exports = { longName = pluginNamespace + PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix; let plugin = null; + if (pluginName.match(/\s+/)) { + const whitespaceError = new Error("Whitespace found in plugin name '" + pluginName + "'"); + + whitespaceError.messageTemplate = "whitespace-found"; + whitespaceError.messageData = { + pluginName: longName + }; + throw whitespaceError; + } + if (!plugins[shortName]) { try { plugin = require(longName); diff --git a/messages/whitespace-found.txt b/messages/whitespace-found.txt new file mode 100644 index 00000000000..eea4efccedb --- /dev/null +++ b/messages/whitespace-found.txt @@ -0,0 +1,3 @@ +ESLint couldn't find the plugin "<%- pluginName %>". because there is whitespace in the name. Please check your configuration and remove all whitespace from 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 ef88c948b93..8d170e2f313 100644 --- a/tests/lib/config/plugins.js +++ b/tests/lib/config/plugins.js @@ -85,6 +85,21 @@ 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 'whitespace '/); + assert.throws(function() { + StubbedPlugins.load("whitespace\t"); + }, /Whitespace found in plugin name/); + assert.throws(function() { + StubbedPlugins.load("whitespace\n"); + }, /Whitespace found in plugin name/); + assert.throws(function() { + StubbedPlugins.load("whitespace\r"); + }, /Whitespace found in plugin name/); + }); + it("should throw an error when a plugin doesn't exist", function() { assert.throws(function() { StubbedPlugins.load("nonexistentplugin");