Fix non-idempotent comment formatting #2101
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The purpose of this change is to fix the following test failure:
What's happening is that the test attempts to format this expression
… where there is a space at column 81 right after the
;Bkr
followed by a newline.The formatter takes that trailing space into account when formatting the expression,
by switching to the "long form" to format the record completion:
… but the formatted result then strips the trailing space from the comment after
formatting (because of the use of
Pretty.removeTrailingWhitespace
). Thenthe second attempt to format the expression goes back to the first
form since the space is gone and now the original form fits in 80 columns.
Normally we would strip trailing whitespace on comments using
stripSpaces
,which has hidden this issue in most cases, but the trailing newline after the space on
column 81 protects the space from being stripped, which is how the property test
caught this issue.
The way I worked around this was to strip trailing whitespace from each line of
the comment so that the formatting algorithm would correctly take that into
account while formatting.