Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

overhacked
Copy link

@overhacked overhacked commented May 11, 2024

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 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

@ytmimi
Copy link
Contributor

ytmimi commented May 21, 2024

@overhacked thanks for the PR. Would you mind also filing an issue for this too.

@overhacked
Copy link
Author

Hello, @ytmimi! Friendly reminder to see if this might be able to be merged? The related issue is at #6168.

src/comment.rs Show resolved Hide resolved
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]>
@overhacked overhacked force-pushed the overhacked/remove_multiple_comment_trailing_lines branch from 5a70671 to f66d7d8 Compare July 31, 2024 20:57
@overhacked
Copy link
Author

@ytmimi, pushed some commits that address your review comments. Now block comments with bare lines can also have their trailing blank lines stripped. Thanks!

@ytmimi
Copy link
Contributor

ytmimi commented Aug 3, 2024

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.

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

Successfully merging this pull request may close these issues.

Trailing blank line removal in doc comments is not idempotent
3 participants