Trim trailing duplicated TokenNewline in VerticalFormat #48
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 previous implementation of removeDuplicatedNewLine removed consecutive 3 or more duplicated TokenNewline tokens. This was expected between blocks and at the end of the file. However, when removing a nested block in a root block and formatting only a body of the block, an extra TokenNewline will be left at the end.
While at the end of the file, there should be at least one TokenNewLine, so we can trim it into only one TokenNewline at the end. We should not trim the last newlines because the last one means the end of line.
The fix does not currently truncate trailing newlines in blocks when formatting the entire file. I think it should be done, but I will postpone it because the implementation would be complicated.
This is a small breaking change for vertical format, but I think it's a bug fix and I expect that the most of the users doesn't care about it, so this will be included in the next patch release.