-
Notifications
You must be signed in to change notification settings - Fork 367
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
Integrate rustfmt #425
Integrate rustfmt #425
Conversation
115efc4
to
78acc22
Compare
fc7cf66
to
706413f
Compare
Nice. 80 char-wide is really really awkward for some of our long-names types and for many of our many-parameter functions. If anything I'd vote for something more like 150, even. |
8e9f5ed
to
b99199d
Compare
1.40 the same as 1.39, but slightly different from 1.38. So, it's not the most stable. But, can't we all just decide on a canonical version up-front?
Hm, true. Upped to 120, and it seems much improved, lmk if you still prefer >=150. |
c20773b
to
b8de015
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.
There's a few awkward results here, but generally looks good.
lightning-net-tokio/src/lib.rs
Outdated
Ok(pause_read) => { | ||
if pause_read { | ||
tokio::spawn( | ||
reader |
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 super awkward. Anything we can do with the defaults so it doesn't make a mess like 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 think changing this default might help: https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#function-calls
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.
Sure, lets try that.
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.
Should be better with this new change!
@@ -65,7 +89,16 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) { | |||
if disconnect { | |||
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false); | |||
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false); | |||
reconnect_nodes(&nodes[0], &nodes[1], (true, true), (0, 0), (0, 0), (0, 0), (0, 0), (false, false)); |
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 also feels a bit awkward, no? Can we make it just put a line per thing if the total line is too long, not just all the time?
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 used to this look from previous formatters but fine with trying something different.
Can we make it just put a line per thing if the total line is too long, not just all the time?
IIUC that is what it is: https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#tall-default
We could change it to this instead: https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#compressed
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.
Hmm, my question was more about when rustfmt decides to put it on new lines...I kinda assumed it was "too long" by char count, but looks like this one shouldn't hit that metric?
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 the formatter fudges the character count a bit such that this line is barely over the limit: https://i.imgur.com/EWGbOBk.png
We could increase the character count again from 120 to 150. that does seem a bit long to me, but not a hill i'm willing to die on 😛
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.
Hmm...So my smallest terminal is 140-wide, though I presume I'm a minority here. Maybe bump again and see where we end up.
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.
Functions with large number of arguments may signal a need to refactor the code. Here, the arguments consisting of long sequences of literals aren't very meaningful to the reader.
Generally, I'd prefer if lines aren't longer than 100-120 characters. @valentinewallace Does fn_args_layout
apply to function definition or calls (or both)?
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.
@jkczyz looks like it applies to both. I also prefer 100-120 character max lines.
fuzz/src/chanmon_consistency.rs
Outdated
monitor) | ||
} } | ||
(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0).unwrap(), monitor) | ||
}}; |
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.
These look like instances of rust-lang/rustfmt#3068 or rust-lang/rustfmt#3858. We'll likely get churn until that is fixed. The first issue seems to imply that it is only a problem when using tabs for indentation.
Does disabling format_macro_bodies
prevent this? We could do that until the issue is fixed.
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.
Done! good idea.
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.
Oh, note that adding unstable features means we can only run the formatter on the rust nightly channel though, which requires adding another travis build and also potentially extra code churn over time. I'm fine with all that, but worth pointing out.
fuzz/src/chanmon_consistency.rs
Outdated
events::MessageSendEvent::UpdateHTLCs { ref node_id, .. } => { | ||
if *node_id != drop_node_id { true } else { false } | ||
}, | ||
if *node_id != drop_node_id { | ||
true | ||
} else { | ||
false | ||
} | ||
} |
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 verbosity here could be eliminated by changing the match arm's body simply to*node_id != drop_node_id
. Not sure if it's worth going down the rabbit hole fixing things of this nature, though.
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.
Hm, new issue, maybe?
b8de015
to
b0ed084
Compare
d06112e
to
8a5bcb6
Compare
My biggest concern would be code churn. The only thing worse than no common format is a common format that requires regular changes and PRs with conflicts. |
e196f92
to
4cd92bf
Compare
@TheBlueMatt is this concern because I switched to using the nightly version? |
Right, as you indicated it might cause churn, but also any inconsistencies in rustfmt would as well - you said 1.38 has different results from 1.39/1.40 which is also concerning. I presume its only getting better so I'm not objecting to it in practice, only noting that any decisions we make wrt policy should prioritize stability of output over most other issues, and that probably means not using unstable features until they stabilize. |
Gotcha, that would also necessitate the removal of @jkczyz objections to prioritizing stability over the usage of |
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.
Gotcha, that'll necessitate the removal of
indent_style = "Visual"
which solved the awkward parts you mentioned in this comment.@jkczyz objections to prioritizing stability over the usage of
match_block_trailing_comma
,format_macro_bodies
andfn_single_line
?
Was writing this up independently but it seems to pertain here...
TL;DR: I'd prefer stability, too, given my assessment below. But without format_macro_bodies
disabled, we're going to get some bad formatting (misaligned braces). Maybe we can find a suitable workaround though.
There appears to be many more unstable than stable ones. I assume enabling them means we are getting the defaults for those even if we don't specify them in the config.
My opinion on the ones we're setting after looking through the code:
match_block_trailing_comma
: Nice for consistency but can do without until stable if necessary.format_macro_bodies
: Disabling is a workaround for the bugs mentioned in Integrate rustfmt #425 (comment). We wouldn't want to disable this once they are resolved. Another workaround is to stop usinghard_tabs
if I'm reading the bug correctly. @TheBlueMatt Should we assume switching to spaces is not an option?indent_style
: Visual indentation of arrays (ec2b4ed#diff-c48f1714e930339b99af4720509c9404R235) and struct initialization seems a bit unnatural (ec2b4ed#diff-39afe74fe704e5d3029c0fd96f7db3b1R212). Applying this across all types of expressions doesn't seem ideal, but it is all or nothing apparently.fn_single_line
: Forces single-line functions rather than just allowing them. Not ideal when line limit is long, IMHO.
Additionally, max_width
is making for long array initializations go across as many lines as elements, which is pretty awkward. But perhaps this is limited to testing/fuzzing code and could be mitigate somehow if undesirable.
fuzz/src/peer_crypt.rs
Outdated
#[inline] | ||
fn slice_to_be16(v: &[u8]) -> u16 { | ||
((v[0] as u16) << 8*1) | | ||
((v[1] as u16) << 8*0) | ||
((v[0] as u16) << 8 * 1) | ((v[1] as u16) << 8 * 0) | ||
} |
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.
Add #[rustfmt::skip]
.
@jkczyz there's about ~100 macros (at least according to |
Good call! 👍 |
b4ccb00
to
90bb8fa
Compare
Can I help with this? |
Right, probably time to rerun this and check to see how stable rustfmt is across rust versions. Probably makes sense to take this after we land the few big-uns for 0.0.11. |
Ran it on the freshest 2 versions, and |
Cool. Wanna rebase this on master? |
90bb8fa
to
f4371a2
Compare
Codecov Report
@@ Coverage Diff @@
## master #425 +/- ##
==========================================
- Coverage 91.12% 91.04% -0.08%
==========================================
Files 34 34
Lines 20544 26049 +5505
==========================================
+ Hits 18720 23716 +4996
- Misses 1824 2333 +509
Continue to review full report at Codecov.
|
5a53aab
to
ff7d747
Compare
00645b6
to
12f1054
Compare
@TheBlueMatt Update:
the stability is this: And 1.36.0 and below are broken due to If I remove EDIT: spoke too soon, build broken now. Gimme a sec |
- Add skips to places where lists get over-expanded. - Add variables to avoid some long function call lines. - Prevent some end-of-line comments from being put onto next line. - re: ChannelContext skip, avoid rustfmt removing a comma because the comma's causes a compilation error
12f1054
to
a7b8d3b
Compare
Opened an issue upstream for the somewhat absurdly tall code this seems to generate. rust-lang/rustfmt#4146 |
Until rustfmt upstream gets its act together and generates sane code, lets close this. We still have an issue to track it. |
Closes #410. @jkczyz let me know any initial feedback!
Some notes:1) I stuck with only "stable" features ofrustfmt
, of which there are only 142) I went with 80-character lines because I like being able to have many vim panes side-by-side, but it looks a bit weird at times. 100 might be better.3) Travis will fail if we run check the formatting w/ multiple rust versions, so I chosestable
for thelightning
crate and1.34.2
for thefuzz
crate.Problem: the build fails on
1.22.0
--rustfmt
only works on1.24.0
and beyond. Are there any plans to deprecate support for 1.22.0, and/or could we possibly bump the minimum supported version of RL to 1.24.0?TODO:
[ ] add a bunch of
#[rustfmt::skip]
s to places that benefit from being aligned in a specific way