Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: improve diagnostics for shareable-config-missing errors (#11880)
  • Loading branch information
not-an-aardvark committed Jun 25, 2019
1 parent 566b7aa commit 056c2aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
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

0 comments on commit 056c2aa

Please sign in to comment.