Permalink
Browse files

Update: Throw error if whitespace found in plugin name (fixes #6854) (#…

  • Loading branch information...
1 parent 4063a79 commit be29599c6e12175c5a48e117526bd204bf82fda5 @jostrander jostrander committed with nzakas Sep 3, 2016
Showing with 28 additions and 0 deletions.
  1. +10 −0 lib/config/plugins.js
  2. +3 −0 messages/whitespace-found.txt
  3. +15 −0 tests/lib/config/plugins.js
View
@@ -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);
@@ -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.
@@ -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");

0 comments on commit be29599

Please sign in to comment.