From 597c217f2c0ac5ca4bd1ddad321f2192a88fc40f Mon Sep 17 00:00:00 2001 From: Calvin Freitas Date: Sun, 9 Jul 2017 11:20:23 -0700 Subject: [PATCH] Fix: confusing error if plugins from config is not an array (#8888) --- lib/config/plugins.js | 12 ++++++++++++ tests/lib/config/plugins.js | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/lib/config/plugins.js b/lib/config/plugins.js index 11852df5c96..adfd8a1bbe3 100644 --- a/lib/config/plugins.js +++ b/lib/config/plugins.js @@ -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); } } diff --git a/tests/lib/config/plugins.js b/tests/lib/config/plugins.js index 00b53af7262..4b165ea4ead 100644 --- a/tests/lib/config/plugins.js +++ b/tests/lib/config/plugins.js @@ -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()", () => {