-
Notifications
You must be signed in to change notification settings - Fork 8
Update recommended rustfmt config #96
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
Open
PoignardAzur
wants to merge
3
commits into
main
Choose a base branch
from
rustfmt_file_2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,19 +24,32 @@ For those files, the formatting produced by `rustfmt` is required. | |
The following rustfmt config is recommended: | ||
|
||
```toml | ||
# LINEBENDER RUSTFMT CONFIG - v1 | ||
# LINEBENDER RUSTFMT CONFIG - v2 | ||
# Ensure lines end with \n even if the git configuration core.autocrlf is not set to true | ||
newline_style = "Unix" | ||
|
||
# `Foobar { foo, bar }` is more readable than `Foo { foo: foo, bar: bar }` | ||
use_field_init_shorthand = true | ||
|
||
# Forces let else blocks to always be their own line(s). | ||
# Enforcing this helps readers scan all early returns of a function at a glance. | ||
single_line_let_else_max_width = 0 | ||
|
||
# Commented out because it is still unstable, but works fine in practice. | ||
# imports_granularity = "Module" | ||
|
||
# END LINEBENDER RUSTFMT CONFIG | ||
``` | ||
|
||
You may also want to occasionally use this unstable config: | ||
|
||
```toml | ||
# Groups imports in a predictable way: first core/alloc/std, then other crates, then the current crate. | ||
group_imports = "StdExternalCrate" | ||
``` | ||
|
||
We don't recommend it as a permanent config value even for nightly projects, because the way it reorders items [isn't always ideal](https://github.com/linebender/linebender.github.io/issues/87). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "exports" rather than "items" here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think "items" is fine for a short description. |
||
|
||
## Markdown | ||
|
||
In Markdown files, every paragraph should have one line per sentence. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Copying my previous review comment from the last time you submitted this:
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.
I disagree, for the reason exposed in the comment above.
I think
is fundamentally different from
and that, unlike the
if else
case, theelse return
case deserves to be spread out no matter its length.In general, I think a control-flow-altering statement should always be on its own line.
(In theory you can do a single line
if x { y } else { return z }
, but only by treating the return statement as an expression, which is rare in practice.)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.
Thank you for providing reasoning. I'm not completely sure I agree; for one thing, no style guide would ever have the formatting:
To be clear, my preference would just be to stick with the default, rather than matching the two at zero; I don't think it's a significant enough win, and IDEs can already highlight exit points for you in a much more complete manner
That being said, I'm not going to argue for it further; e.g. the Xilem repository which already has this set has literally no occurrences which would be formatted on a single line anyway.