-
Notifications
You must be signed in to change notification settings - Fork 888
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
Add flatten_imports
config option (inverse of merge_imports
)
#4553
Conversation
Thank you for the PR @maackle. I don't know if you've had an opportunity to review the highly related RFC in rust-lang/style-team#140, but if not would strongly encourage you to do so. The short version is that we need to move to a different, single enum-based option that allows users to control how imports are formatted, and that will support multiple strategies. I appreciate the effort you've put into this, but adding a separate boolean based option would be taking us in the opposite direction so this won't be mergeable as-is. If you're interested in changing the approach to better align with the strategy settled on in the RFC that would be fantastic, but no worries if not! |
@calebcartwright thanks for the detailed response pointing that out. The effort wasn't great, it took me about 15 minutes to put it all together (the code is really clean so it was easy!), so I'd be happy to eventually reformat this to match the RFC. However, reading the RFC, it seems that there is a stated desire to allow multiple import formatting strategies, but no strategies other than "merge" actually exist at the moment. So, perhaps this should wait until some other strategies get decided on and gathered under an enum? If I'm reading that wrong let me know. |
There's also the issue tracking stabilization of the original
Well, certainly the current behavior (which will continue to be the default) of doing nothing/preserving the original exists, and then IIRC with Some of the other strategies, like crate/everything may not be strictly applicable to
There's actually nothing but a lack of bandwidth preventing the first steps of this process from occurring. The first steps would be:
Then, should you or anyone else be interested in the item/flatten/java style, that variant and formatting approach could be added independently of any of the other variants/strategies. There's definitely a strong community desire for this strategy, and I think the only real outstanding question would be what to name the variant and the associated bikeshedding |
Thanks again for the PR @maackle, but I think I'm going to go ahead and close this PR given the above discussion and overall planned strategy for supporting import merging/flattening |
The title says it all, and
Configurations.md
shows it in action.In doing a huge refactor that involved moving large chunks of code from one crate to another, I found it crucial to be able to flatten imports so that the import paths I needed to change were easily greppable, which is not the case for nested imports. Without this option, I would have had to do hundreds of manual import tweaks.
This is not thoroughly tested, especially around
self
imports, but worked fine for my use case, which is a large codebase with a variety of imports (https://github.com/holochain/holochain). If you think this would be a good addition, it needs a stabilization tracking issue before merging. I'd be happy to help with any loose ends, too.