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

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

Merged
merged 1 commit into from May 5, 2023

Conversation

nzakas
Copy link
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

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

* the config file.
*/
async function locateConfigFileToUse({ configFile, cwd }) {

// determine where to load config file from
let configFilePath;
let basePath = cwd;
let error = false;
Copy link
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
Member

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
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
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
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
22 checks passed
@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