diff --git a/lib/config/config-file.js b/lib/config/config-file.js index 179a0ff5e4c7..176329d75135 100644 --- a/lib/config/config-file.js +++ b/lib/config/config-file.js @@ -475,7 +475,14 @@ function loadObject(configContext, { config: configObject, filePath, configFullN // ensure plugins are properly loaded first if (config.plugins) { - configContext.plugins.loadAll(config.plugins); + try { + configContext.plugins.loadAll(config.plugins); + } catch (pluginLoadErr) { + if (pluginLoadErr.messageTemplate === "plugin-missing") { + pluginLoadErr.messageData.configStack.push(filePath); + } + throw pluginLoadErr; + } } // include full path of parser if present diff --git a/tests/lib/config/config-file.js b/tests/lib/config/config-file.js index ff0e41c93cc8..fd7bd4e3f66d 100644 --- a/tests/lib/config/config-file.js +++ b/tests/lib/config/config-file.js @@ -160,7 +160,7 @@ describe("ConfigFile", () => { }, /Failed to load config "plugin:enable-nonexistent-parser\/baz" to extend from./); }); - it("should throw an error with a message template when a plugin is not found", () => { + it("should throw an error with a message template when a plugin referenced for a plugin config is not found", () => { try { ConfigFile.applyExtends({ extends: "plugin:nonexistent-plugin/baz", @@ -179,6 +179,28 @@ describe("ConfigFile", () => { assert.fail("Expected to throw an error"); }); + it("should throw an error with a message template when a plugin in the plugins list is not found", () => { + try { + ConfigFile.loadObject(configContext, { + config: { + plugins: ["nonexistent-plugin"] + }, + filePath: "/whatever", + configFullName: "configName" + }); + } catch (err) { + assert.strictEqual(err.messageTemplate, "plugin-missing"); + assert.deepStrictEqual(err.messageData, { + pluginName: "eslint-plugin-nonexistent-plugin", + pluginRootPath: getFixturePath("."), + configStack: ["/whatever"] + }); + + return; + } + assert.fail("Expected to throw an error"); + }); + it("should apply extensions recursively when specified from package", () => { const config = ConfigFile.applyExtends({ extends: "recursive-dependent",