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

chore: Add rustfmt.toml with some unstable format options #477

Merged
merged 5 commits into from
Jan 31, 2025

Conversation

sbernauer
Copy link
Member

@sbernauer sbernauer commented Jan 15, 2025

Fixup of #136
Back in the day I put it in the wrong folder 🤦‍♂️ We already have this in secret-op for ~2 years now.

The amount of time I have seen suggestions regarding merging imports and sorting (std, external, crate), I'm very happy that we can solve all of that by automation 🥳

cargo +stable fmt currently gives a warning, but still returns exit code 0 (so can be ignored)
Use cargo fmt to run the formatting.

See #136

For what it's worth, you can run a single cargo command using the nightly toolchain by using cargo +nightly fmt.

Rust-Analyzer should also allow you to set rustfmt-specific flags (for Emacs, put (setq rust-rustfmt-switches '("+nightly" "--edition" "2018")) into your .emacs), and I assume Rust-IntelliJ has something similar.

@sbernauer sbernauer requested review from nightkr, soenkeliebau, Techassi and a team January 15, 2025 07:45
@sbernauer sbernauer self-assigned this Jan 15, 2025
@sbernauer sbernauer requested a review from razvan January 15, 2025 07:46
razvan
razvan previously approved these changes Jan 15, 2025
@sbernauer
Copy link
Member Author

@siegfriedweber had a good point that this might result in back and forth changes between developer machines with different nightly versions.
We could pin a specific nightly version, but that implies some maintenance burden.

As kube is also using a nightly formatter I would like to give it a try and see if that is really the case. In that case we should be able to pin a specific nightly version

@nightkr
Copy link
Member

nightkr commented Jan 15, 2025

Pinning sounds good to me. It's not like we'd need to bump this more often than we already do for rustc anyway.

@sbernauer
Copy link
Member Author

We decided to go with this in a daily last week. If there are any problems we can always revert this change

@sbernauer sbernauer requested a review from Techassi January 28, 2025 09:13
@Techassi
Copy link
Member

Techassi commented Jan 31, 2025

VS Code users can use the following setting to override the command run on "Format on save":

"rust-analyzer.rustfmt.overrideCommand": [
  "rustfmt",
  "+nightly-2025-01-15",
  "--edition",
  "2021",
  "--"
],

Sadly, setting extraArgs did not work:

"rust-analyzer.rustfmt.extraArgs": [
  "+nightly-2025-01-15",
  "--edition",
  "2021"
],

I assume, the configuration for other editors will be similar.

@sbernauer sbernauer added this pull request to the merge queue Jan 31, 2025
Merged via the queue into main with commit 458ab02 Jan 31, 2025
2 checks passed
@sbernauer sbernauer deleted the chore/add-rustfmt branch January 31, 2025 09:41
@Techassi
Copy link
Member

Techassi commented Jan 31, 2025

I also found two potentially interesting options to enable (which shouldn't be too controversial):

It might be worth to add them in a separate PR.

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

Successfully merging this pull request may close these issues.

4 participants