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’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

Closed
wants to merge 1 commit into from

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Apr 5, 2024

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.

@G-Rath G-Rath requested a review from a team as a code owner April 5, 2024 22:54
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Apr 5, 2024
@github-actions github-actions bot added cli Relates to ESLint's command-line interface core Relates to ESLint's core APIs and features labels Apr 5, 2024
Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit af9507e
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/661081274f0c6d000884f3c8

@fasttime fasttime added the accepted There is consensus among the team that this change meets the criteria for inclusion label Apr 8, 2024
Comment on lines +398 to +400
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!");
}
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

I'll take this.

@G-Rath G-Rath marked this pull request as draft April 8, 2024 22:30
@G-Rath G-Rath closed this Apr 19, 2024
@G-Rath G-Rath deleted the handle-undefined-config-better branch April 19, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion cli Relates to ESLint's command-line interface core Relates to ESLint's core APIs and features feature This change adds a new feature to ESLint
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Change Request: explicitly handle undefined being passed as a config value
4 participants