-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
feat: Better error message for flat config plugins #17399
Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
messages/eslintrc-plugins.js
Outdated
A config object has a "plugins" key defined as an array of strings. | ||
|
||
Flat config requires "plugins" to be an object in this form: | ||
|
||
{ | ||
plugins: { | ||
${plugins[0] || "namespace"}: pluginObject | ||
} | ||
} |
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.
Flat config schema throws this error on any array (it doesn't check whether it's an array of strings), so if the user specifies plugins like this:
module.exports = [{
plugins: [somePluginObject]
}];
The printed message will look like this:
Oops! Something went wrong! :(
ESLint: 8.45.0
A config object has a "plugins" key defined as an array of strings.
Flat config requires "plugins" to be an object in this form:
{
plugins: {
[object Object]: pluginObject
}
}
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#importing-plugins-and-custom-parsers
If you're using a shareable config that you cannot rewrite in flat config format, then use the compatibility utility:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
Perhaps we should have two templates?
plugins
is an array of strings (or empty array?) - possible eslintrc config, use this templateplugins
is an array but not array of strings - use another template.
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.
I think for now I'd like to keep things simple and just assume that when people are using an array then they are most likely using an eslintrc-style config. We can always expand later if we find that's not the case.
I've updated to check if the first item in the array is a string to make sure that the message makes sense.
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
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.
There is a conflict that needs to be resolved. |
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 when merge conflicts are resolved.
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.
Just a typo, and a merge conflict that needs to be fixed. Otherwise LGTM.
Co-authored-by: Francesco Trotta <github@fasttime.org>
Should be all set. Please double-check that the merge makes sense. |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[x] 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)
Made it so that if the
plugins
key is defined as an array, then we throw a specific validation message that lets people know it's an eslintrc style config that needs to be converted. I also added a section on the config migration guide to include details on usingFlatCompat
.Refs #17370
Is there anything you'd like reviewers to focus on?
Does the wording make sense?