Skip to content

fix: Ensure FlatESLint#findConfigFile() doesn't throw.#17151

Merged
mdjermanovic merged 1 commit into
mainfrom
find-config-file-fix
May 5, 2023
Merged

fix: Ensure FlatESLint#findConfigFile() doesn't throw.#17151
mdjermanovic merged 1 commit into
mainfrom
find-config-file-fix

Conversation

@nzakas
Copy link
Copy Markdown
Member

@nzakas nzakas commented May 4, 2023

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

If findConfigFile() can't find eslint.config.js, it now returns undefined instead of throwing an error.

Fixes #17150

Is there anything you'd like reviewers to focus on?

Did I miss any edge cases?

If findConfigFile() can't find eslint.config.js, it now returns
undefined instead of throwing an error.

Fixes #17150
@nzakas nzakas requested a review from a team as a code owner May 4, 2023 21:15
@eslint-github-bot eslint-github-bot Bot added the bug ESLint is working incorrectly label May 4, 2023
@netlify
Copy link
Copy Markdown

netlify Bot commented May 4, 2023

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 43d4e2c
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/64542068e4b549000817bbb5

Comment thread lib/eslint/flat-eslint.js
// determine where to load config file from
let configFilePath;
let basePath = cwd;
let error = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The name error sounds generic and I expected it to be an instance of Error. Can we use something like isConfigFileDetected/hasConfigFile? I feel it's better suited for a boolean value.

Copy link
Copy Markdown
Member

@aladdin-add aladdin-add May 5, 2023

Choose a reason for hiding this comment

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

Or we can return an error object error = new Error("Could not find config file.");, which can be thrown directly where it is used?

    const { configFilePath, basePath, error } = await locateConfigFileToUse({ configFile, cwd });

    // config file is required to calculate config
    if (error) {
        throw error;
    }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@aladdin-add I like that suggestion. Can you open a PR with that change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sure, will do!

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label May 5, 2023
Copy link
Copy Markdown
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

Works well! If the above discussion is not resolved before today's release, I'll merge this as is and we can consider refactoring in a follow up.

@mdjermanovic mdjermanovic merged commit f076e54 into main May 5, 2023
@mdjermanovic mdjermanovic deleted the find-config-file-fix branch May 5, 2023 19:57
aladdin-add added a commit to aladdin-add/eslint that referenced this pull request May 6, 2023
@eslint-github-bot eslint-github-bot Bot locked and limited conversation to collaborators Nov 2, 2023
@eslint-github-bot eslint-github-bot Bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: FlatESLint#findConfigFile should return undefined if it doesn't find eslint.config.js

4 participants