Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Improve error reporting when extending missing config (fixes … #8100

Merged
merged 1 commit into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/config/config-file.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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