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

Feature Request: rustfmt.toml Inheritance (Directory-Level Overrides Via Multiple rustfmt.toml's) #5445

Closed
tmillr opened this issue Jul 15, 2022 · 2 comments

Comments

@tmillr
Copy link

tmillr commented Jul 15, 2022

I feel like there should exist a way to be able to utilize multiple rustfmt.toml's for a single project. For example, tsconfig.json allows an extends key for this very purpose. Basically all config from an arbitrarily-named base file is loaded, then the normal/usual rustfmt.toml file is also loaded and any keys found in the normal config file which also overlap with the base config take precedence (overriding the corresponding base keys). Finally, both files are combined in order to derive the ultimate/final configuration that will be used. This allows for a single global/base config while also allowing a per-project/per-directory override as needed and uses regular rustfmt.toml files which can then be easily tracked and committed (unlike trying to override a base config by passing extra args to rustfmt itself). Also it seems that by default most plugins and such simply invoke rustfmt without any extra options but the file path or content, so relying on command-line arguments for setting or overriding options isn't really a great solution (doesn't really seem "portable" without manual user-intervention/re-configuration of existing tools/plugins, or a 3rd-party solution, etc.).

In my opinion, the current practice of only allowing a single config file seems to be somewhat limiting and can only be worked-around via a combination of unpleasant hacks (like writing a script to manually parse rustfmt.toml's, watching for changes to the global/base config file with e.g. watchman or vim autocommands, locating and updating all of my own "derived" rustfmt.toml files whenever the global rustfmt.toml changes). For my own personal/side-projects, I kinda would like to have my own set of global preferences that are used for every such repo I start that are also kept in sync whenever those preferences change, all while permitting per-repo overrides for the hypothetical use-case where incorporating particular settings into a global rustfmt.toml would not be appropriate (or, would conflict with my usual/regular preferences that I want for most repos).

I apologize in advance if this issue already exists. I did a quick search beforehand and found similar, but distinct, feature requests (such as file or method level overrides). I'm still getting a feel for GitHub in general.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 15, 2022

Thanks for reaching out!

No worries about still getting used to GitHub. I find myself struggling to find things in the issue tracker all the time. Is #5313 similar to what you're proposing here?

@calebcartwright
Copy link
Member

I think there's a few items in this, a large part of which is actually just the inheritance/merging of files as implemented in #4179.

That's definitely one we should backport, and which addresses the main thrust of this.

However, I'm not willing to take on an arbitrary extends key as suggested as part of the issue. It's a non-trivial effort that still has bugs in the JS/TS space even with the plethora of libraries that deliver those capabilities. As detailed in the first section of our configuration documentation, global config files are already supported so really the only missing piece is the merging, which a backport of #4179 would address.

I don't think there's anything actionable for us here beyond the backport which I've already labeled, so I'm going to close. Feel free to ask any follow up questions though.

@calebcartwright calebcartwright closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2022
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

No branches or pull requests

3 participants