-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Introduce a rustfmt.toml file with nightly features #4541
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I recommend you enable it and look at some diffs. I don't particularly like it, but it may be my lack of experience. |
I played with this for a bit, and setting it to If we decide to set it, I can do it and rebase this PR. |
d84ab4c
to
54e4219
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alcuadrado this is a great addition!
I tried out the use_small_heuristics = "Max"
option and I have a weak preference against it, as I prefer to see chained methods in a vertical layout.
I noticed that we don't cache the Rust toolchain installations currently so I added a backlog issue for that: NomicFoundation/edr#221
Yeah, same here. |
Let's not change the For, |
54e4219
to
b96bccf
Compare
Rebased against |
This PR introduces a
rustfmt.toml
that uses some nightly features and makes the necessary setup changes for it to work.The first 5 commits implement the necessary setup to use nightly exclusively for rustfmt, while still compiling with stable. This includes the devcontainer (you need to rebuild it), the ci, pre-commit hook, and vscode settings.
Then, each of the following commits enable a rustfmt feature, and automatically reformat the code.
The features enabled are:
import_granularity
: Controls how the import statements are merged. In this case, it automatically merges every import from the same crate, so that there's only 1 import per crate.wrap_comments
: Automatically wrap comments.group_imports
: Groups imports in three groups (i.e.std
,core
, andalloc
; external crates; andself
,super
, andcrate
).Features 1 and 2 were discussed with @Wodann. Feature 3 looked interesting to me (we use an equivalent in TS), but I have no strong opinions about it.
Other interesting features:
comment_width
: So that there's less wrapping.use_small_heuristics
: This controls how oftenrustfmt
introduces newlines. I saw multiple projects set it to"Max"
, so that lines are longer. For example,rust-analyzer
uses it.