Skip to content

Commit

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

0 comments on commit 5aeeff6

Please sign in to comment.