-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this 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.
lib/config/rule-validator.js
Outdated
@@ -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.`); |
There was a problem hiding this comment.
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.
lib/config/rule-validator.js
Outdated
error.messageTemplate = "config-plugin-missing"; | ||
error.messageData = { pluginName, ruleId }; |
There was a problem hiding this comment.
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
lib/config/rule-validator.js
Outdated
const finalError = errorMessage === "" ? error : new TypeError(errorMessage); | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
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. |
There was a problem hiding this 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.
lib/config/rule-validator.js
Outdated
|
||
let errorMessage = `${errorMessageHeader}: Could not find plugin "${pluginName}" in configuration.`; | ||
|
||
const missingPluginError = errorMessage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency
const missingPluginError = errorMessage; | |
const missingPluginErrorMessage = errorMessage; |
lib/config/rule-validator.js
Outdated
throw new TypeError(errorMessage); | ||
const error = new TypeError(errorMessage); | ||
|
||
if (errorMessage === missingPluginError) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (errorMessage === missingPluginError) { | |
if (errorMessage === missingPluginErrorMessage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks.
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
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 isIs there anything you'd like reviewers to focus on?
fixes #19254