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

Introduce a rustfmt.toml file with nightly features #4541

Merged
merged 7 commits into from
Oct 30, 2023
Merged

Conversation

alcuadrado
Copy link
Member

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:

  1. 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.
  2. wrap_comments: Automatically wrap comments.
  3. group_imports: Groups imports in three groups (i.e. std, core, and alloc; external crates; and self, super, and crate).

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 often rustfmt introduces newlines. I saw multiple projects set it to "Max", so that lines are longer. For example, rust-analyzer uses it.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2023

⚠️ No Changeset found

Latest commit: b96bccf

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

@vercel
Copy link

vercel bot commented Oct 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 30, 2023 9:27pm
hardhat-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 30, 2023 9:27pm

@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Oct 29, 2023
@alcuadrado
Copy link
Member Author

  • use_small_heuristics: This controls how often rustfmt introduces newlines. I saw multiple projects set it to "Max", so that lines are longer. For example, rust-analyzer uses it.

I recommend you enable it and look at some diffs. I don't particularly like it, but it may be my lack of experience.

@alcuadrado
Copy link
Member Author

I played with this for a bit, and setting it to 100 would preserve most comments unchanged, so I believe that was the intended width.

If we decide to set it, I can do it and rebase this PR.

Copy link
Member

@agostbiro agostbiro left a 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

@alcuadrado
Copy link
Member Author

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.

Yeah, same here.

@Wodann
Copy link
Member

Wodann commented Oct 30, 2023

Let's not change the use_small_heuristics for the reasons mentioned above.

For, comment_width, the width of comments in the PR matches the max length of code lines, which looks good to me.

@alcuadrado
Copy link
Member Author

Rebased against edr/main. I'll merge once the CI passes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:ready This issue is ready to be worked on
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants