Commit 3810d50
committed
Stop breaking line comments at a no-break space
JavaCommentsHelper wraps a line comment that is too long at the last
whitespace before the limit, and CharMatcher.whitespace() counts the
no-break space U+00A0 as whitespace. The continuation line then starts
with "//" and that no-break space. LINE_COMMENT_MISSING_SPACE_PREFIX,
whose \s does not match it, takes that for a comment with no space after
the slashes, so the next run pads it, breaks at the no-break space again
and leaves the padding behind as an empty "//" line. Every run adds one,
and the file never settles (#38, from google/google-java-format#562).
Line comments now break only at breaking whitespace, which leaves out
U+00A0, U+2007 and U+202F: a no-break space is by definition not a place
to break a line. A number grouped with no-break spaces now moves to the
next line whole instead of being cut inside.
The new golden covers both shapes. The 15,747 files of the JDK 21
sources format exactly as before; none of them contains a no-break
space.1 parent 53ac7d8 commit 3810d50
3 files changed
Lines changed: 22 additions & 2 deletions
File tree
- open-java-format/src
- main/java/com/palantir/javaformat/java
- test/resources/com/palantir/javaformat/java/testdata
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments