Skip to content

Commit

Permalink
Update: Improve error message when extend config missing (fixes #6115) (
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto authored and gyandeeps committed Feb 20, 2017
1 parent f62a724 commit 360dbe4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/config/config-file.js
Expand Up @@ -390,6 +390,13 @@ function applyExtends(config, filePath, relativeTo) {
debug(`Loading ${parentPath}`);
return ConfigOps.merge(load(parentPath, false, relativeTo), previousValue);
} catch (e) {
if (parentPath.indexOf("plugin:") === 0 || parentPath.indexOf("eslint:") === 0) {
e.message = `Failed to load config "${parentPath}" to extend from.`;
e.messageTemplate = "extend-config-missing";
e.messageData = {
configName: parentPath
};
}

/*
* If the file referenced by `extends` failed to load, add the path
Expand Down
3 changes: 3 additions & 0 deletions messages/extend-config-missing.txt
@@ -0,0 +1,3 @@
ESLint couldn't find the config "<%- configName %>" to extend from. Please check that the name of the config is correct.

If you still have problems, please stop by https://gitter.im/eslint/eslint to chat with the team.
36 changes: 35 additions & 1 deletion tests/lib/config/config-file.js
Expand Up @@ -199,7 +199,7 @@ describe("ConfigFile", () => {

});

it("should throw an error when extends config is not found", () => {
it("should throw an error when extends config module is not found", () => {

const configDeps = {
"../util/module-resolver": createStubModuleResolver({})
Expand All @@ -216,6 +216,40 @@ describe("ConfigFile", () => {

});

it("should throw an error when an eslint config is not found", () => {

const configDeps = {
"../util/module-resolver": createStubModuleResolver({})
};

const StubbedConfigFile = proxyquire("../../../lib/config/config-file", configDeps);

assert.throws(() => {
StubbedConfigFile.applyExtends({
extends: "eslint:foo",
rules: { eqeqeq: 2 }
}, "/whatever");
}, /Failed to load config "eslint:foo" to extend from./);

});

it("should throw an error when a plugin config is not found", () => {

const configDeps = {
"../util/module-resolver": createStubModuleResolver({})
};

const StubbedConfigFile = proxyquire("../../../lib/config/config-file", configDeps);

assert.throws(() => {
StubbedConfigFile.applyExtends({
extends: "plugin:foo",
rules: { eqeqeq: 2 }
}, "/whatever");
}, /Failed to load config "plugin:foo" to extend from./);

});

it("should apply extensions recursively when specified from package", () => {

const resolvedPaths = [
Expand Down

0 comments on commit 360dbe4

Please sign in to comment.