Skip to content

Commit

Permalink
Update: Throw error if whitespace found in plugin name (fixes #6854) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jostrander authored and nzakas committed Sep 3, 2016
1 parent 4063a79 commit be29599
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/config/plugins.js
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions 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.
15 changes: 15 additions & 0 deletions tests/lib/config/plugins.js
Expand Up @@ -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");
Expand Down

0 comments on commit be29599

Please sign in to comment.