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

Scripts: Try using cosmiconf for locating tool configs #30842

Open
ockham opened this issue Apr 14, 2021 · 1 comment
Open

Scripts: Try using cosmiconf for locating tool configs #30842

ockham opened this issue Apr 14, 2021 · 1 comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Tool] WP Scripts /packages/scripts [Type] Enhancement A suggestion for improvement.

Comments

@ockham
Copy link
Contributor

ockham commented Apr 14, 2021

A number of our scripts in the @wordpress/scripts contain logic to find the relevant config and/or ignore file (or package.json entry) for a given tool by replicating that tool's logic in doing so. E.g. lint-js tries to locate the relevant config for eslint here:

// See: https://eslint.org/docs/user-guide/configuring#using-configuration-files-1.
const hasLintConfig =
hasArgInCLI( '-c' ) ||
hasArgInCLI( '--config' ) ||
hasProjectFile( '.eslintrc.js' ) ||
hasProjectFile( '.eslintrc.json' ) ||
hasProjectFile( '.eslintrc.yaml' ) ||
hasProjectFile( '.eslintrc.yml' ) ||
hasProjectFile( 'eslintrc.config.js' ) ||
hasProjectFile( '.eslintrc' ) ||
hasPackageProp( 'eslintConfig' );

Similar strategies can be found across our other scripts. This has lead to creation of helper methods such as hasProjectFile or hasPackageProp.

Rather than replicating and hard-wiring those tools' strategies, we might consider using a tool like cosmiconf, which seeks to establish somewhat of a standard for config file retrieval across tools. (Here's a broader discussion in the nodejs/tooling repo that had a similar goal but didn't really go anywhere.) AFAIK, some of the tools we use actually use cosmiconf themselves (e.g. prettier), while it has been proposed (but not yet adopted) by others (e.g. eslint).

We could consider multiple strategies:

  • Audit our tools, and only switch those to cosmiconf that use it themselves.
  • Use it for all our tools, as we might consider it "good enough".

Inspired by #30240 (comment)

@ockham ockham added [Type] Enhancement A suggestion for improvement. [Tool] WP Scripts /packages/scripts labels Apr 14, 2021
@gziolo gziolo added the Needs Dev Ready for, and needs developer efforts label Apr 15, 2021
@gziolo
Copy link
Member

gziolo commented Apr 15, 2021

We might have an issue with the same proposal already. It was surely discussed in the past but no actions were taken. If you look at the list of possible files used with different tools you will see that there isn't one standard enforced. Anyway, it'd be nice to have cosmiconf integrated 👍🏻

@gziolo gziolo added the Good First Issue An issue that's suitable for someone looking to contribute for the first time label Apr 16, 2021
@gziolo gziolo changed the title Scripts: Consider using cosmiconf for locating tool configs Scripts: Try using cosmiconf for locating tool configs Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Tool] WP Scripts /packages/scripts [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants