-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: show an explicit message when undefined
is included as a config
#18276
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
if (fileConfig.includes(void 0)) { | ||
throw new Error("You have included `undefined` in your array of configs - this is commonly the result of trying to use a config from a plugin that does not exist; make sure you have not typo'd the name!"); | ||
} |
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 function only loads configs for the ESLint
class, not for Linter
or RuleTester
.
Maybe it would be better to add this check in @humanwhocodes/config-array
in normalize
and normalizeSync
, where it will run for all usages, and to make the error message more generic. What do you think @nzakas?
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 don't mind that, but I figured the error message might be ESLint specific meaning it shouldn't belong in config-array
; I don't think it's a big deal for RuleTester
not to do this (since that is usually used for unit type tests and can easily be verified with tools like TypeScript) but I could see it being more useful for Linter
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.
So I think what we want to do here is throw an error from config-array
during normalize
and normalizeSync
that includes the index of the offending item (calling rethrowConfigError()
. Then in ESLint we can catch that error and display an ESLint-specific message.
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.
@G-Rath would you like to submit a PR to https://github.com/humanwhocodes/config-array?
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.
Yup this is still on my radar, just been a bit busy - I hope to put something up in the next week or so, but feel free to make the pr if you want it sooner
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'll take this.
Fixes #18259
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)
I've included an explicit check for
undefined
being present in the configs array that causes an error to be thrown with a message indicating a common source for this value being present.Is there anything you'd like reviewers to focus on?
I have no strong feelings about the message or tests - I've gone with something I think is ok but by no means think its perfect I'd like input from the core team as I feel they'll know better what kind of style and wording would fit best to align with related content in docs and other messaging in the tool itself.