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

Fix: improve diagnostics for shareable-config-missing errors #11880

Merged
merged 1 commit into from Jun 25, 2019
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
11 changes: 6 additions & 5 deletions lib/cli-engine/config-array-factory.js
Expand Up @@ -224,15 +224,16 @@ function loadPackageJSONConfigFile(filePath) {
/**
* Creates an error to notify about a missing config to extend from.
* @param {string} configName The name of the missing config.
* @param {string} importerName The name of the config that imported the missing config
* @returns {Error} The error object to throw
* @private
*/
function configMissingError(configName) {
function configMissingError(configName, importerName) {
return Object.assign(
new Error(`Failed to load config "${configName}" to extend from.`),
{
messageTemplate: "extend-config-missing",
messageData: { configName }
messageData: { configName, importerName }
}
);
}
Expand Down Expand Up @@ -637,7 +638,7 @@ class ConfigArrayFactory {
return this._loadConfigData(eslintAllPath, name);
}

throw configMissingError(extendName);
throw configMissingError(extendName, importerName);
}

/**
Expand Down Expand Up @@ -670,7 +671,7 @@ class ConfigArrayFactory {
);
}

throw plugin.error || configMissingError(extendName);
throw plugin.error || configMissingError(extendName, importerPath);
}

/**
Expand Down Expand Up @@ -704,7 +705,7 @@ class ConfigArrayFactory {
} catch (error) {
/* istanbul ignore else */
if (error && error.code === "MODULE_NOT_FOUND") {
throw configMissingError(extendName);
throw configMissingError(extendName, importerPath);
}
throw error;
}
Expand Down
2 changes: 2 additions & 0 deletions messages/extend-config-missing.txt
@@ -1,3 +1,5 @@
ESLint couldn't find the config "<%- configName %>" to extend from. Please check that the name of the config is correct.

The config "<%- configName %>" was referenced from the config file in "<%- importerName %>".

If you still have problems, please stop by https://gitter.im/eslint/eslint to chat with the team.
3 changes: 2 additions & 1 deletion tests/lib/cli-engine/cli-engine.js
Expand Up @@ -3338,7 +3338,8 @@ describe("CLIEngine", () => {
} catch (err) {
assert.strictEqual(err.messageTemplate, "extend-config-missing");
assert.deepStrictEqual(err.messageData, {
configName: "nonexistent-config"
configName: "nonexistent-config",
importerName: getFixturePath("module-not-found", "extends-js", ".eslintrc.yml")
});
return;
}
Expand Down