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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Corrected notice for invalid (:) plugin names #13473

Merged
merged 7 commits into from Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions lib/cli-engine/config-array-factory.js
Expand Up @@ -802,7 +802,7 @@ class ConfigArrayFactory {
*/
_loadExtendedPluginConfig(extendName, ctx) {
const slashIndex = extendName.lastIndexOf("/");
const pluginName = extendName.slice("plugin:".length, slashIndex);
const pluginName = slashIndex === -1 ? extendName : extendName.slice("plugin:".length, slashIndex);
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
const configName = extendName.slice(slashIndex + 1);

if (isFilePath(pluginName)) {
Expand Down Expand Up @@ -994,7 +994,7 @@ class ConfigArrayFactory {
error = resolveError;
/* istanbul ignore else */
if (error && error.code === "MODULE_NOT_FOUND") {
error.messageTemplate = "plugin-missing";
error.messageTemplate = request.indexOf(":") === -1 ? "plugin-missing" : "plugin-invalid";
error.messageData = {
pluginName: request,
resolvePluginsRelativeTo: ctx.pluginBasePath,
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/naming.js
Expand Up @@ -43,7 +43,7 @@ function normalizePackageName(name, prefix) {
*/
normalizedName = normalizedName.replace(/^@([^/]+)\/(.*)$/u, `@$1/${prefix}-$2`);
}
} else if (!normalizedName.startsWith(`${prefix}-`)) {
} else if (!normalizedName.startsWith(`${prefix}-`) && normalizedName.indexOf(":") === -1) {
normalizedName = `${prefix}-${normalizedName}`;
}

Expand Down
9 changes: 9 additions & 0 deletions messages/plugin-invalid.txt
@@ -0,0 +1,9 @@
ESLint couldn't find the plugin "<%- pluginName %>".

(The package "<%- pluginName %>" was not found when loaded as a Node module from the directory "<%- resolvePluginsRelativeTo %>".)

It looks like this might not be a valid plugin name. Did you use the name of a preset configuration instead of a plugin?
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved

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

If you still can't figure out the problem, please stop by https://eslint.org/chat to chat with the team.
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions tests/lib/cli-engine/config-array-factory.js
Expand Up @@ -1503,6 +1503,24 @@ describe("ConfigArrayFactory", () => {
}, /Failed to load config "plugin:invalid-config\/bar" to extend from./u);
});

it("should throw an error with a message template when a plugin referenced for a plugin config is invalid", () => {
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
try {
applyExtends({
extends: "plugin:nonexistent-plugin",
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
rules: { eqeqeq: 2 }
});
} catch (err) {
assert.strictEqual(err.messageTemplate, "plugin-invalid");
assert.deepStrictEqual(err.messageData, {
pluginName: "plugin:nonexistent-plugin",
resolvePluginsRelativeTo: process.cwd(),
importerName: "whatever"
});
return;
}
assert.fail("Expected to throw an error");
});

it("should throw an error with a message template when a plugin referenced for a plugin config is not found", () => {
try {
applyExtends({
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/shared/naming.js
Expand Up @@ -25,7 +25,8 @@ describe("naming", () => {
["@z\\foo", "@z/eslint-config-foo"],
["@z\\foo\\bar.js", "@z/eslint-config-foo/bar.js"],
["@z/eslint-config", "@z/eslint-config"],
["@z/eslint-config-foo", "@z/eslint-config-foo"]
["@z/eslint-config-foo", "@z/eslint-config-foo"],
["plugin:invalid", "plugin:invalid"]
], (input, expected) => {
it(`should return ${expected} when passed ${input}`, () => {
const result = naming.normalizePackageName(input, "eslint-config");
Expand Down