Skip to content

Conversation

@Mirko-von-Leipzig
Copy link
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig commented Dec 2, 2025

I'm experimenting with using awk to reflow comment lines.

The awk script is generated via AI (because doing this manually.. !@#% that :)).

Flow is basically:

  1. Run reflow.sh
    • This uses the AI generated awk script to merge consecutive comment lines together with some additional rules to account for edge case e.g. code blocks.
    • Comment lines are now too long since they've merged
  2. Run cargo +nightly fmt --all to truncate the overly long comment lines again
  3. ..profit?

It should handle and be considerate of

  • Normal comments, doc comments
  • Markdown headings
  • Lists
  • Code fences
  • Preserve indentation
  • Our ============... delimiters
  • Ignores generated code and target directory
  • Preserves empty comment lines

In addition I've modified the makefile to include the flow. The fmt checker in CI now runs the flow and ensures that the diff is zero.

@Mirko-von-Leipzig Mirko-von-Leipzig added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Dec 2, 2025
Copy link
Collaborator Author

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

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

I think this actually worked very well.

Comment on lines +106 to +107
// diesel::joinable!(notes -> accounts (sender)); diesel::joinable!(transactions -> accounts
// (account_id));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is one outlier which is "malformatted" but I think likely we should place this in a code fence or something.

I'm leaving this as is for now just for discussion's sake.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, should have been a code block in the first place - or deleted.


// The rebuild is automatically triggered by `build.rs` as described in
// <https://docs.rs/diesel_migrations/latest/diesel_migrations/macro.embed_migrations.html#automatic-rebuilds>.
// The rebuild is automatically triggered by `build.rs` as described in <https://docs.rs/diesel_migrations/latest/diesel_migrations/macro.embed_migrations.html#automatic-rebuilds>.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line is arguably worse as well now, but its because the link exceeds the limit and rustfmt doesn't know what to do. This might behave better if it was a doc comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be great to have an opt out way for it, i.e. like clang-format. But the awk is already scarily complex.

Copy link
Collaborator Author

@Mirko-von-Leipzig Mirko-von-Leipzig Dec 4, 2025

Choose a reason for hiding this comment

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

I mean we can probably get it to respect some kind of // [rustfmt::skip] pretty easily. But I think in this case its a problem with the < ... >

@@ -1,5 +1,4 @@
// This build.rs is required to trigger the `diesel_migrations::embed_migrations!` proc-macro in
// `store/src/db/migrations.rs` to include the latest version of the migrations into the binary, see <https://docs.rs/diesel_migrations/latest/diesel_migrations/macro.embed_migrations.html#automatic-rebuilds>.
// This build.rs is required to trigger the `diesel_migrations::embed_migrations!` proc-macro in `store/src/db/migrations.rs` to include the latest version of the migrations into the binary, see <https://docs.rs/diesel_migrations/latest/diesel_migrations/macro.embed_migrations.html#automatic-rebuilds>.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also a failure point; unclear why except rustfmt thought this was the way to do it 🤷

@Mirko-von-Leipzig Mirko-von-Leipzig marked this pull request as ready for review December 2, 2025 07:49
@Mirko-von-Leipzig Mirko-von-Leipzig changed the title ci: experiment with comment reflow using awk ci: reflow comments using awk Dec 2, 2025
}

next
}
Copy link
Contributor

Choose a reason for hiding this comment

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

End of poor-mans-markdown parser 😰

}

END { if(in_comment) print out_prefix merged }

Copy link
Contributor

Choose a reason for hiding this comment

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

I've such an itch to fixup cargo-spellcheck reflow now...

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

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants