-
Notifications
You must be signed in to change notification settings - Fork 892
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
fix: remove multiple trailing lines in comments #6163
base: master
Are you sure you want to change the base?
fix: remove multiple trailing lines in comments #6163
Conversation
2df498f
to
fd95d0f
Compare
@overhacked thanks for the PR. Would you mind also filing an issue for this too. |
Previously, rustfmt would remove one blank, trailing line in a comment every time it ran, so formatting was not idempotent if a comment had multiple trailing lines. Comments are only reformatted in this way if `comment::rewrite_comment_inner` is called, which is enabled by any of the config options `normalize_comments`, `wrap_comments`, or `format_code_in_doc_comments` (for doc comments only). Absent those config options, no trailing line reformatting occurs at all. In this commit, when the existing condition that detects a blank, trailing line is true, any preceding blank lines are removed from the reformatted comment. A source/target "system test" was added to prevent regression. Signed-off-by: Ross Williams <[email protected]>
Block comments with bare lines are handled differently than those without bare lines (unless `normalize_comments` is configured). If `normalize_comments` is false but `wrap_comments` is true, trailing blank lines should be removed from block comments, including those with bare lines. Signed-off-by: Ross Williams <[email protected]>
5a70671
to
f66d7d8
Compare
@ytmimi, pushed some commits that address your review comments. Now block comments with bare lines can also have their trailing blank lines stripped. Thanks! |
Great! I appreciate you looking into that. I know this has been open for a while and it'll be a bit longer before I'm able to take another look at this since the team's top priority right now is completing the work around style edition 2024. I'll follow up once I'm able to review this. |
Previously, rustfmt would remove one blank, trailing line in a comment every time it ran, so formatting was not idempotent if a comment had multiple trailing lines. Comments are only reformatted in this way if
comment::rewrite_comment_inner
is called, which is enabled by any of the config optionsnormalize_comments
,wrap_comments
, orformat_code_in_doc_comments
(for doc comments only). Absent those config options, no trailing line reformatting occurs at all.In this fix, when the existing condition that detects a blank, trailing line is true, any preceding blank lines are removed from the reformatted comment. A source/target "system test" was added to prevent regression.
Fixes #6168