Skip to content

Add support for a simple config file #125

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

Merged
merged 1 commit into from
Aug 1, 2022

Conversation

molawson
Copy link
Contributor

@molawson molawson commented Aug 1, 2022

Following on from conversation in #124, I'm taking a pass at what I think is a useful but fairly simple approach to supporting a config file. I'd love to hear any and all feedback on this. I see this as a viable solution in particular but also as a means to have more concrete discussions about the topic generally.

Context

As syntax_tree gains wider usage, it'll be very helpful to allow projects to commit their particular configs within their repo for use by any tool that uses stree instead of having to create wrapper scripts, rely on rake tasks that come with their own overhead, or manually keep settings up to date among all contributors.

Approach

This set of changes takes inspiration from Sorbet to provide users with a simple config file that's also easy to parse and use within the gem. It's a text file that has the exact options you'd pass on the command line, each on their own line. These are parsed and prepended to the arguments array within CLI.run, still allowing for other options to passed from the command line.

Limiting Scope (and Future Extensions)

I decided to restrict this only to the command line options and avoid the source files argument, opting to let other tools pass their own source file from the command line, which is preferable for tools like editor integrations that might interact with a single file at a time. If users want to interact with all of their Ruby files at once, the rake tasks are perfect for providing larger, static patterns of files. And since they use CLI.run as well, they'll pick up options from a .syntax_tree file, if present.

I also opted for only supporting a single .syntax_tree file at the project root. If there's a need for multiple configs or config locations, this can be easily extended to look up through a directory structure or accept an option for a specific config file location (or even a different filename). Those felt out of scope for this initial support.

@kddnewton
Copy link
Member

Looking at the code, I'm actually more amenable to this than I was. It's pretty clean, and I'm less worried about maintaining it than I was.

A couple of small tweaks and I'll merge this:

  • Can you change the name of the file to .streerc? I'm hesitant to use .syntax_tree because that makes me think it might be used at runtime even if the CLI isn't used. Naming it after the executable makes me think it's for configuring the CLI.
  • Can you put the name of the file into a constant and then reference that constant in the tests? That'll make it a little more maintainable if we change it in the future.

@molawson
Copy link
Contributor Author

molawson commented Aug 1, 2022

Thanks for taking a look so quickly! I'm happy to make both of those changes.

@molawson molawson force-pushed the config-file-support branch from b0da11d to 0b459c9 Compare August 1, 2022 20:05
As syntax_tree gains wider usage, it'll be very helpful to allow
projects to commit their particular configs within their repo for use by
any tool that uses `stree` instead of having to create wrapper scripts,
rely on rake tasks that come with their own overhead, or manually keep
settings up to date among all contributors.

This set of changes takes inspiration from sorbet to provide users with
a simple config file that's also easy to parse and use within the gem.
It's a text file that has the exact options you'd pass on the command
line, each on their own line. These are parsed and prepended to the
arguments array within `CLI.run`, still allowing for other options to
passed from the command line.

I decided to restrict this only to the command line options and avoid
the source files argument, opting to let other tools pass their own
source file from the command line, which is preferable for tools like
editor integrations that might interact with a single file at a time. If
users want to interact with all of their Ruby files at once, the rake
tasks are perfect for providing larger, static patterns of files. And
since they use `CLI.run` as well, they'll pick up options from a
.streerc file, if present.

I also opted for only supporting a single .streerc file at the project
root. If there's a need for multiple configs or config locations, this
can be easily extended to look up through a directory structure or
accept an option for a specific config file location (or even a
different filename). Those felt out of scope for this initial support.
@molawson molawson force-pushed the config-file-support branch from 0b459c9 to bd85cd5 Compare August 1, 2022 20:07
@kddnewton kddnewton merged commit 3b81273 into ruby-syntax-tree:main Aug 1, 2022
@kddnewton
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants