-
Notifications
You must be signed in to change notification settings - Fork 928
Stop extra newlines from being added after block comments #1185
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
Conversation
Could you add a test for this please? |
Sure, will do. |
Travis bug looks spurious to me. |
// check that there are no contained block comments | ||
if !subslice.chars() | ||
.filter(|&c| c != '\t' && c != ' ') | ||
.collect::<String>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be done more efficiently? Am I right that you only want to trim leading whitespace? So you should be able to use trim and then contains, without needing to collect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not just leading, but all whitespace besides newlines, as subslice
in this case would be // comment \n /* block comment */
, which trim wouldn't work on. Although I guess I could also split by newlines and check the start of every trimmed line, which might be a little bit faster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other solution is to change the CommentCodeSlices
iterator so that it actually processes them separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
splitting by lines seems fine to me, I think
bump? |
Thanks, sorry for the delay. Github does not notify me when you push a commit, so you need to also comment so I see the changes. |
Thanks for the change, looks good! |
This PR closes #1177. Essentially rustfmt was reformatting the whole string of
// comment \n /* block comment */
, but was only checking the beginning of that string to determine whether it was a line comment or not, and thus adding the extra newline.