Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: confusing error if plugins from config is not an array (#8888)
  • Loading branch information
calvinf authored and not-an-aardvark committed Jul 9, 2017
1 parent 3c1dd6d commit 597c217
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/config/plugins.js
Expand Up @@ -156,8 +156,20 @@ class Plugins {
* @param {string[]} pluginNames An array of plugins names.
* @returns {void}
* @throws {Error} If a plugin cannot be loaded.
* @throws {Error} If "plugins" in config is not an array
*/
loadAll(pluginNames) {

// if "plugins" in config is not an array, throw an error so user can fix their config.
if (!Array.isArray(pluginNames)) {
const pluginNotArrayMessage = "ESLint configuration error: \"plugins\" value must be an array";

debug(`${pluginNotArrayMessage}: ${JSON.stringify(pluginNames)}`);

throw new Error(pluginNotArrayMessage);
}

// load each plugin by name
pluginNames.forEach(this.load, this);
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/config/plugins.js
Expand Up @@ -236,6 +236,10 @@ describe("Plugins", () => {
assert.equal(rules.get("example2/bar"), plugin2.rules.bar);
});

it("should throw an error if plugins is not an array", () => {
assert.throws(() => StubbedPlugins.loadAll("example1"), "\"plugins\" value must be an array");
});

});

describe("removePrefix()", () => {
Expand Down

0 comments on commit 597c217

Please sign in to comment.