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

Auto-format imports using Module granularity #702

Merged
merged 8 commits into from
Dec 13, 2023

Conversation

Xanewok
Copy link
Contributor

@Xanewok Xanewok commented Dec 11, 2023

Part of #155

This is going to be a fun one 😆

I've pushed two preview commits: the first one imports using the Crate granularity, the other one with Module granularity.

Disclaimer: I'm biased 😃 I've used this style since I started using Rust and it's also being used by vast majority of projects in the ecosystem that I've used or looked at; it's also used by the Rust compiler, Cargo and the tools like Rustfmt or Clippy.

Here's a summary of the possible options: rust-lang/rustfmt#3362.

Here is an RFC discussion about setting on a variant: rust-lang/style-team#140, I highly recommend reading it.
To give a brief summary, it seems that people stand behind two options:

  • Module - good trade-off between readability and conciseness
  • Item - minimizes conflicts when many people edit the same files often

To bring back some of the arguments raised in favor of the Module and explain some of my reasoning as well:

  • it naturally settles on the module as the, well, module/boundary from which items can be imported...
  • thus, helps build the intuition how to use and structure Rust crates
  • less verbose than Java-style (Item) imports, which can often explode and take unreasonable amount of space (and we don't really benefit enough from minimized conflicts as we probably won't be a team of 50 or the like)...
  • but repeats enough information to quickly trace a module path rather than having to reconstruct the paths from the crate-style use import tree...
  • and already often takes less space in our case, line-wise;
  • quite good greppability

@Xanewok Xanewok requested a review from a team as a code owner December 11, 2023 12:59
Copy link

changeset-bot bot commented Dec 11, 2023

⚠️ No Changeset found

Latest commit: 32db801

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@OmarTawfik OmarTawfik left a comment

Choose a reason for hiding this comment

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

Left one suggestion about super::* imports, but not blocking.

@Xanewok Xanewok added this pull request to the merge queue Dec 13, 2023
Merged via the queue into NomicFoundation:main with commit 51e5b61 Dec 13, 2023
1 check passed
@Xanewok Xanewok deleted the imports-formatting branch December 13, 2023 11:48
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.

3 participants