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: improve how configures are resolved #26

Merged
merged 8 commits into from
Apr 5, 2024
Merged

feat: improve how configures are resolved #26

merged 8 commits into from
Apr 5, 2024

Conversation

antfu
Copy link
Collaborator

@antfu antfu commented Apr 5, 2024

fix #25

  • Configs now resolved with find-up, aligning with ESLint
  • When no arguments are provided, the cwd will be changed to the directory for the found config file
  • When config path is provided, the cwd will keep at the command cwd
  • When root path is provided but not the config, the config will be searched from the root path

src/cli.ts Outdated Show resolved Hide resolved
@antfu antfu changed the title feat(cli): improve how configures are resolved feat: improve how configures are resolved Apr 5, 2024
@eslint eslint deleted a comment from eslint-github-bot bot Apr 5, 2024
src/configs.ts Outdated

const configPath = userConfigPath
? resolve(cwd, userConfigPath)
: await findUp(configFilenames, { cwd: userRootPath || cwd })
Copy link
Member

Choose a reason for hiding this comment

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

Instead of recreating the same logic from ESLint, could you use ESLint#findConfigFile()?

Copy link
Collaborator Author

@antfu antfu Apr 5, 2024

Choose a reason for hiding this comment

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

Since the flat config is just a JS module, I found it's great that you can just import it directly to get the resolved configs - that's what this project was built upon originally. While I pretty much want to share the code, I don't want it to be coupled with users' ESLint version, or specific API that ESLint made public. Right now, the config searching logic isn't complicated; I guess it's ok not to keep it standalone and portable right now. For sure, I am still open to sharing logic if needed in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. My only concern is keeping it in sync if things change, but if we launch from ESLint we can always pass in the specific config file and base path, so maybe not that big of an issue.

*/
chdir?: boolean
}

export async function readConfig(
Copy link
Member

Choose a reason for hiding this comment

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

Can you add some JSDoc for this function so it's easier to understand what exactly is being passed in?

@antfu antfu merged commit 264c58f into main Apr 5, 2024
7 checks passed
@antfu antfu deleted the feat/config-path branch April 5, 2024 21:37
@github-actions github-actions bot mentioned this pull request Apr 5, 2024
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.

Ability to pass in a config file path and base path
2 participants