Skip to content

Commit

Permalink
Ensure latest config is present in config stack for plugin-missing er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
not-an-aardvark committed Feb 20, 2019
1 parent ecfb5f5 commit c3c04ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/config/config-file.js
Expand Up @@ -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
Expand Down
24 changes: 23 additions & 1 deletion tests/lib/config/config-file.js
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit c3c04ab

Please sign in to comment.