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: improved errors when config can not be found #85

Merged
merged 2 commits into from
Aug 19, 2024

Conversation

voxpelli
Copy link
Contributor

Fixes #82

When encountering no flat config it now checks for a legacy config and if found it will output this error message now:

Skärmavbild 2024-08-15 kl  15 03 25

And if no legacy config file is found either, then it will tell the user what files it looked for and in what folder:

Skärmavbild 2024-08-15 kl  15 03 43

src/configs.ts Outdated
@@ -83,13 +140,19 @@ export async function resolveConfigPath(options: ResolveConfigPathOptions) {
*/
export async function readConfig(
options: ReadConfigOptions,
): Promise<{ configs: FlatConfigItem[], payload: Payload, dependencies: string[] }> {
): Promise<ConfigPathLegacyError | ConfigPathError | { configs: FlatConfigItem[], payload: Payload, dependencies: string[] }> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we use throw instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@antfu As throws are not typed in TypeScript and can be intertwined with other kinds of exceptions

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could throw and use if (error instanceof ConfigPathLegacyError) to do the type guard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but not sure it would make the code simpler :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it would make it more complicated either - but I think the point is that errors are supposed to be thrown, and loadConfig by it's name should returns the config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry that I never got to fixing this 🙈

Speaking on this topic, ran into this standard proposal the other day: https://github.com/arthurfiorette/proposal-safe-assignment-operator

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries at all.

Yeah I saw it. Would love to see it landed someday!

@antfu antfu merged commit 748590e into eslint:main Aug 19, 2024
7 checks passed
@github-actions github-actions bot mentioned this pull request Aug 15, 2024
@voxpelli voxpelli deleted the voxpelli/issue82 branch August 19, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot find Eslint config file
2 participants