-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add rustfmt rules to the project. #575
Conversation
You can check what the code looks like and decide whether it is okay or not=) |
We actually can remove it because it is very fas check(~10 seconds) =) |
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.
We actually had a custom rustfmt config, then removed it in #22. Generally, using any config that isn't the default is a bit iffy, since it invites bikeshedding: some people prefer one thing, other prefer another. By keeping everything at default as a rule, there's no bikeshedding possible on individual preferences.
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 think its a good thing to have a fmt standard. But then if we are diverging from the default of rustfmt, we might want to enforce that to all our repos so we don't end up having different styles across the org
@@ -0,0 +1,64 @@ | |||
max_width = 90 # changed |
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.
Won't reducing from the default 100
to 90
cause a lot of wrapping? I already feel a bit constrained with the default 100, also considering that almost everyone uses wide screens
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'm using only a laptop=) The default value is 120. I didn't try 100 by I know that with 90, it always fits into GitHub split mode review=)
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.
the default value is 100 -> https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=#max_width
wrap_comments = false | ||
format_code_in_doc_comments = false | ||
comment_width = 80 | ||
normalize_comments = true # changed |
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.
That is cool, but isn't stable yet:
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.
Many fields from here are unstable=) It is why it is nightly rust fmt
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.
Hmmm. Does this require users to switch between nightly
and stable
to run cargo fmt
? The codebase itself builds with stable
.
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.
where_single_line = false | ||
imports_indent = "Block" | ||
imports_layout = "Vertical" # changed | ||
imports_granularity = "Crate" # changed |
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 personally prefer Module
. Things get a bit confusing, maybe even unreadable, if we have multiple nested levels - whereas they are most of the times just single lines if its per module
https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=#Module%5C%3A
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.
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.
the cfg flag can go both ways. For example, it is also likely that a cfg flag will affect a subset of imports within a crate, rather than the entire crate.
use crate::{ThingA, ThingB}
#[cfg(feature = "feature-c")]
use crate::ThingC
Will rustfmt avoid collapsing the import if we have a cfg flag on a specific set of imports from a crate?
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.
fn_args_layout = "Tall" | ||
brace_style = "SameLineWhere" | ||
control_brace_style = "AlwaysSameLine" | ||
trailing_semicolon = false # changed |
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.
This one is very good
edition = "2021" # changed | ||
version = "One" | ||
merge_derives = true | ||
use_try_shorthand = true # changed |
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.
This is cool too, but try is so old that we don't even see it anymore. Anyway, its definitely something we should have
90f5a69
to
1d889ca
Compare
Yea, if we are okay to apply rustfmt for |
If this requires an org-wide change then it should have org-wide buy-in. Might be time to follow-up on FuelLabs/rfcs#8 |
1d889ca
to
00812fc
Compare
Reviewed all the config options, apart from maybe |
95a8a78
to
a3d321d
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.
lgtm, but since this is a big change plz wait for at least one other approval before merging.
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.
lgtm as well
@adlerjohn we need to update the ci requirements on the repo to merge this pr |
@xgreenx can you also update |
cf5146d
to
8251f7b
Compare
Added rustfmt rules. I used my favorite rules but we can discuss your wishes=)
It requires usage of nightly rustfmt because it contains many new configurations.
Formatted the whole project, so it will make ongoing PR harder(you need to fix conflicts)
Added CI to check the fmt.