Skip to content

Conversation

@davidBar-On
Copy link
Contributor

Closes #4824

The suggested fix is in two code changes done for Version Two - by adding trim_start() before passing a comments string to rewrite_comment().

A more robust fix may be to do the trim_start() (or even trim()) inside rewrite_comment() (for Version Two), but I didn't evaluate the overall use of rewrite_comment() to make sure this is o.k.

Comment on lines 281 to 284

let other_lines = &subslice[offset + 1..];
let other_lines = &subslice[offset + 1..].trim_start();
let comment_str =
rewrite_comment(other_lines, false, comment_shape, self.config)
.unwrap_or_else(|| String::from(other_lines));
.unwrap_or_else(|| other_lines.to_string());
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to trim the start of the comment if we fail to rewrite it? By the time we call unwrap_or_else other_lines has already been trimmed. Maybe we should leave the string alone if rewrite_comment fails?

let other_lines = &subslice[offset + 1..];
let comment_str = 
    rewrite_comment(other_lines.trim_start(), false, comment_shape, self.config)
        .unwrap_or_else(|| other_lines.to_string());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree this is better. Changed.

@ytmimi
Copy link
Contributor

ytmimi commented Aug 25, 2022

For what it's worth, I had a similar idea of removing the leading whitespace in #5392.

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.

Multiline comment causes error[internal]: left behind trailing whitespace

2 participants