Skip to content

Rustfmt Maximalism - #3749

Closed
joostjager wants to merge 2 commits into
lightningdevkit:mainfrom
joostjager:fmt-maximalism
Closed

Rustfmt Maximalism#3749
joostjager wants to merge 2 commits into
lightningdevkit:mainfrom
joostjager:fmt-maximalism

Conversation

@joostjager

@joostjagerjoostjager commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

Just enable it globally. We can take care of format refactors later or as we update the code, and this way we immediately eliminate the ongoing formatting micro-penalties.

To auto-format in-flight PRs without manual conflict resolution:

Let's say commit X is the commit where all of main is rustfmt'ed. Nothing other dan cargo fmt should have been done in this commit.

  • First rebase the branch normally onto the predecessor of X (still without formatting) to resolve any outstanding conflicts.
  • Create and checkout a new branch for the rewrite off of X.
  • Run the following script, replace BRANCH with the branch to replay:
#!/bin/bashecho Start
BRANCH="2025-04-rustfmt-tests-1"forcommitin$(git rev-list --reverse HEAD..$BRANCH);doecho"Commit: $commit"
git restore --source=$commit.
cargo fmt
git add .
git commit -c $commit --no-edit --allow-empty
done
  • Now every commit in the new branch is rustfmted and exists on top of formatted main.

@ldk-reviews-bot

ldk-reviews-bot commented Apr 25, 2025

Copy link
Copy Markdown

👋 I see @wpaulino was un-assigned.
If you'd like another reviewer assignemnt, please click here.

@joostjager
joostjager marked this pull request as ready for review April 25, 2025 13:15
@joostjager
joostjager removed the request for review from wpaulinoApril 25, 2025 13:16
@tnull
tnull requested a review from TheBlueMattApril 25, 2025 16:02

@tnulltnull left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed I get the same output by running cargo fmt

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK if you review any follow-ups to fix things up after this :)

Comment on lines +879 to +897
'a,
'b,
'c,
'd,
'e,
'f,
'logger,
'h,
'i,
'j,
'graph,
'k,
'mr,
SD,
M,
T,
F,
C,
L,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sheesh

@benthecarmanbenthecarman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're so back

Comment on lines +3729 to +3730
flags & FundedStateFlags::ALL
== FundedStateFlags::LOCAL_SHUTDOWN_SENT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fits on one line. Is there something about our config that would cause it to split it over two lines?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that rustfmt wants to put the == on the same line, pushing the total == FundedStateFlags::LOCAL_SHUTDOWN_SENT | FundedStateFlags::REMOTE_SHUTDOWN_SENT to column 101. So expected behavior afaik.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's bitwise not logical OR.

@joostjager
joostjager requested a review from jkczyzApril 26, 2025 00:09
@joostjagerjoostjager added the weekly goal Someone wants to land this this week label Apr 26, 2025
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

2 similar comments
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@carlaKCcarlaKC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, matches local cargo fmt

Comment threadci/rustfmt.sh
for file in $(comm -23 "$TMP_FILE" rustfmt_excluded_files); do
echo "Checking formatting of $file"
rustfmt $VERS --edition 2021 --check "$file"
done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONTRIBUTING.md needs update to remove reference to contrib/run-rustfmt.sh

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, will fix after rebase

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@dunxendunxen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually leaning toward this PR's approach and biting the bullet. I don't believe it's that cumbersome to existing PRs with your suggested solution.

Running cargo +1.63 fmt (MSRV-shipped rustfmt), I get the same output.

@joostjager

Copy link
Copy Markdown
ContributorAuthor

To be sure we wouldn't get any problems with in-flight prs, I tried the filter-branch command from the PR description on #3751: joostjager/rust-lightning@main-fmt...joostjager:rust-lightning:rustfmt-tests-rewritten

@joostjager

Copy link
Copy Markdown
ContributorAuthor

Another option that could be used is #[rustfmt::skip] on the method level, for code that turns out unreadable beyond personal preference.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

After rebasing my own rustfmt stuff I realized that the main rebase logic won't actually work in some cases around indentation changes. Because git sometimes mis-identifies hunks as non-conflict it'll end up duplicating some lines.

@joostjager

joostjager commented May 2, 2025

Copy link
Copy Markdown
ContributorAuthor

After rebasing my own rustfmt stuff I realized that the main rebase logic won't actually work in some cases around indentation changes. Because git sometimes mis-identifies hunks as non-conflict it'll end up duplicating some lines.

I didn't run into this yet, but had identified the potential problem too. Updated the PR description with a new approach that strictly avoids any type of merge logic / automatic conflict resolution.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 3rd Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 9th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 10th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 10th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 11th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 11th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 12th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 12th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 13th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 13th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 14th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 14th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 15th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 15th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 16th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 16th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 17th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 17th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 18th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 18th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 19th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 19th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 20th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 20th Reminder

Hey @TheBlueMatt@jkczyz@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@wpaulino
wpaulino removed their request for review June 11, 2025 00:03
@joostjagerjoostjager mentioned this pull request Jun 12, 2025
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 21st Reminder

Hey @TheBlueMatt@jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 22nd Reminder

Hey @TheBlueMatt@jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 23rd Reminder

Hey @TheBlueMatt@jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@joostjager

Copy link
Copy Markdown
ContributorAuthor

Closing this PR. We went with the incremental #[rustfmt::skip] approach (#3809)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rustfmtweekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@joostjager@ldk-reviews-bot@TheBlueMatt@tnull@dunxen@jkczyz@valentinewallace@benthecarman@carlaKC