Skip to content

chore: better error message for missing plugin in config #19402

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

Merged
merged 4 commits into from
Feb 19, 2025

Conversation

Tanujkanti4441
Copy link
Contributor

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[x] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

To modify the error message for missing plugin in config, created a new file config-plugin-missing to store message related to possible reasons of the error.

Message is kind of similar to what suggested in #19254 (comment) which is

Oops! Something went wrong! :(

ESLint: 9.17.0

TypeError: Key "rules": Key "simple-import-sort/imports": Could not find plugin "simple-import-sort" in the configuration for file /path/to/file.js.

Common causes of this problem include:

1. The "simple-import-sort" plugin is not defined in your configuration file. 
2. "simple-import-sort" is defined in a configuration object that that doesn't match /path/to/file.js.

Use the Config Inspector (--inspect-config) to check your configuration file and which parts match path/to/file.js.

since it wasn't clear to me what /path/to/file.js exactly indicates in this error, so i tried to write something that can help to find issue, that is

Oops! Something went wrong! :(
ESLint: 9.17.0

TypeError: Key "rules": Key "simple-import-sort/imports": Could not find plugin "simple-import-sort" in the configuration.

Common causes of this problem include:

1. The "simple-import-sort" plugin is not defined in your configuration file.
2. The "simple-import-sort" plugin is not defined within the same configuration object in which the "simple-import-sort/imports" rule is applied.

Is there anything you'd like reviewers to focus on?

fixes #19254

@Tanujkanti4441 Tanujkanti4441 requested a review from a team as a code owner February 4, 2025 14:22
@eslint-github-bot eslint-github-bot bot added the chore This change is not user-facing label Feb 4, 2025
@github-actions github-actions bot added the core Relates to ESLint's core APIs and features label Feb 4, 2025
Copy link

netlify bot commented Feb 4, 2025

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 67716db
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/67b4bc1fd03e3900087276fc
😎 Deploy Preview https://deploy-preview-19402--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just a bit of cleanup.

The path/to/file.js was meant to be the path of the file that was being linted when the error occurred. That's because you might have the plugin defined in a config that doesn't match this file.

@@ -36,7 +36,12 @@ function throwRuleNotFoundError({ pluginName, ruleName }, config) {
const ruleId = pluginName === "@" ? ruleName : `${pluginName}/${ruleName}`;

const errorMessageHeader = `Key "rules": Key "${ruleId}"`;
let errorMessage = `${errorMessageHeader}: Could not find plugin "${pluginName}".`;
const error = new TypeError(`${errorMessageHeader}: Could not find plugin "${pluginName}" in configuration.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to create the error here. If we wait until the end (like it is in HEAD) then we can avoid a lot of this extra code.

Just set the errorMessage here.

Comment on lines 41 to 42
error.messageTemplate = "config-plugin-missing";
error.messageData = { pluginName, ruleId };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be moved to just above throw

Comment on lines 71 to 72
const finalError = errorMessage === "" ? error : new TypeError(errorMessage);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary if we only set errorMessage before the if statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i summarize all three suggestions then it looks something like this i think:

let errorMessage = `${errorMessageHeader}: Could not find plugin "${pluginName}" in configuration.`;

if (config.plugins && config.plugins[pluginName]) {
errorMessage = 'some other error message';
}

const error = new TypeError(errorMessage);

error.messageTemplate = "config-plugin-missing";
error.messageData = { pluginName, ruleId };

throw error;

but won't it effect the error message assigned within the if statement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're talking about messageTemplate? Yes, you're right, we probably want to clear its value if the message changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label Feb 16, 2025
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't realize I forgot to submit my review.


let errorMessage = `${errorMessageHeader}: Could not find plugin "${pluginName}" in configuration.`;

const missingPluginError = errorMessage;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency

Suggested change
const missingPluginError = errorMessage;
const missingPluginErrorMessage = errorMessage;

throw new TypeError(errorMessage);
const error = new TypeError(errorMessage);

if (errorMessage === missingPluginError) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (errorMessage === missingPluginError) {
if (errorMessage === missingPluginErrorMessage) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@github-actions github-actions bot removed the Stale label Feb 17, 2025
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@nzakas nzakas merged commit dab5478 into eslint:main Feb 19, 2025
30 checks passed
@Tanujkanti4441 Tanujkanti4441 deleted the missing-plugin-message branch February 20, 2025 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore This change is not user-facing core Relates to ESLint's core APIs and features
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Change Request: Improve error message when a plugin's rules are enabled without the plugin
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy