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 23, 2016
1 parent 3a1763c commit e4fcfd4
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 @@ -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 eslint-plugin-" + pluginNameWithoutPrefix);

whitespaceError.messageTemplate = "whitespace-found";
whitespaceError.messageData = {
pluginName: pluginNameWithoutPrefix
};
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 "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 @@ -85,6 +85,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 e4fcfd4

Please sign in to comment.