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: Provide helpful error message for nullish configs #18357
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
* A config array is set up in this order: | ||
* 1. Base config | ||
* 2. Original configs | ||
* 3. User-defined configs | ||
* 4. CLI-defined configs |
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.
A CLI-defined config is what gets passed to the overrideConfig
option of the ESLint
constructor? When that fails normalization, it's unclear what the index in the error message is meant to be:
import { ESLint } from "eslint";
const eslint = new ESLint({ overrideConfig: [undefined] });
await eslint.lintFiles("*.js");
When running the above code with node in the eslint repo directory, the error message will be
TypeError: Config (unnamed): Unexpected undefined config at user-defined index 24.
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.
Also ignorePatterns
.
There is no easy way to determine when CLI flags have been added from inside the config array, so I think this error is okay for now.
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.
Maybe configIndex
and location
(base, original, user-defined, ignore-pattern, etc.) should be added as metadata to each config before normalization, because they are known at that time regardless of the order in which the configs are inserted into the config array. Then, when an error occurs, there would be no need to calculate them back based on the final index.
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 like the idea! 👍
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.
That would require a lot of extra work for very little extra value. Because we're talking about an array, there are many different ways configs could potentially be added.
I think what I have here is good enough for where we are right now. It provides helpful context without much overhead. If we find that this doesn't serve our purpose in the future, we can revisit.
Co-authored-by: Francesco Trotta <[email protected]>
Co-authored-by: Francesco Trotta <[email protected]>
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! Leaving open for another approval.
Merging now to get this change in v9.1.0. |
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)
Upgraded
@humanwhocodes/config-array
to include new error details, then updatedFlatConfigArray
to use that info to produce an error message containing the index of the config that caused the error.fixes #18259
Is there anything you'd like reviewers to focus on?
I used the terms "original", "base", and "user-defined" to differentiate between the different parts of the config array. I'm not sure how accurate those are but they are at least indicating the different parts of the array where the error occurred.