Skip to content

Commit 1895394

Browse files
cushonronshapiro
authored andcommitted
Don't wrap // MOE: line comments
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=231858210
1 parent f6561e3 commit 1895394

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

core/src/main/java/com/google/googlejavaformat/java/JavaCommentsHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ private List<String> wrapLineComments(
117117
int length = matcher.group(1).length();
118118
line = Strings.repeat("/", length) + " " + line.substring(length);
119119
}
120+
if (line.startsWith("// MOE:")) {
121+
// don't wrap comments for https://github.com/google/MOE
122+
result.add(line);
123+
continue;
124+
}
120125
while (line.length() + column0 > options.maxLineLength()) {
121126
int idx = options.maxLineLength() - column0;
122127
// only break on whitespace characters, and ignore the leading `// `

core/src/test/java/com/google/googlejavaformat/java/FormatterTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,22 @@ public void blankLinesImportComment() throws FormatterException {
453453
assertThat(RemoveUnusedImports.removeUnusedImports(withoutBlank)).isEqualTo(withoutBlank);
454454
assertThat(ImportOrderer.reorderImports(withoutBlank)).isEqualTo(withoutBlank);
455455
}
456+
457+
@Test
458+
public void dontWrapMoeLineComments() throws Exception {
459+
assertThat(
460+
new Formatter()
461+
.formatSource(
462+
"class T {\n"
463+
+ " // MOE: one long incredibly"
464+
+ " unbroken sentence moving from topic to topic so that no-one had a"
465+
+ " chance to interrupt;\n"
466+
+ "}\n"))
467+
.isEqualTo(
468+
"class T {\n"
469+
+ " // MOE: one long incredibly"
470+
+ " unbroken sentence moving from topic to topic so that no-one had a"
471+
+ " chance to interrupt;\n"
472+
+ "}\n");
473+
}
456474
}

0 commit comments

Comments
 (0)