Skip to content

Commit b24961c

Browse files
committed
Make FormatStringConcatenation an error
Eight calls in the tests built a message or an expected string by concatenation and handed it to a method that formats one itself: AssertJ's describedAs, hasMessage and isEqualTo(String, Object...) and Guava's checkState. They now pass a format string and its arguments.
1 parent 821d50c commit b24961c

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ tasks.withType(JavaCompile).configureEach {
5555
// Checks whose findings have been fixed, build-breaking so that new ones are fixed too rather than read past.
5656
tasks.withType(JavaCompile).configureEach {
5757
options.errorprone {
58+
error('FormatStringConcatenation')
5859
error('RefactorSwitch')
5960
error('SameNameButDifferent')
6061
error('UnusedVariable')

‎gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/FormatDiffTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private void runCommandInRepo(String... args) throws IOException, InterruptedExc
104104
process.getErrorStream().transferTo(baos);
105105
String stderr = baos.toString(UTF_8);
106106

107-
Preconditions.checkState(process.exitValue() == 0, "Expected return code of 0: " + stderr);
107+
Preconditions.checkState(process.exitValue() == 0, "Expected return code of 0: %s", stderr);
108108
}
109109

110110
private static Stream<FormatterService> getFormatters() throws IOException {

‎open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatConfigurableTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void showsTheActiveFormatterAsThePageStands() throws Throwable {
176176

177177
useNativeImage.setSelected(true);
178178
assertThat(activeFormatter().getText())
179-
.isEqualTo("Need to download version " + pluginVersion + " from Maven Central");
179+
.isEqualTo("Need to download version %s from Maven Central", pluginVersion);
180180

181181
path.setText("/opt/open-java-format");
182182
assertThat(activeFormatter().getText()).isEqualTo("/opt/open-java-format");
@@ -268,7 +268,7 @@ void refusesAPathThatIsNotAnExecutableFile() throws Throwable {
268268

269269
assertThatThrownBy(configurable::apply)
270270
.isInstanceOf(ConfigurationException.class)
271-
.hasMessage(missing + " is not an executable file");
271+
.hasMessage("%s is not an executable file", missing);
272272
});
273273
}
274274

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void format() {
7979
tests.writeFormatterOutput(name, output);
8080
return;
8181
}
82-
assertThat(output).describedAs("bad output for " + name).isEqualTo(expected);
82+
assertThat(output).describedAs("bad output for %s", name).isEqualTo(expected);
8383
} catch (FormatterException e) {
8484
throw new RuntimeException(String.format("Formatter crashed on %s", name), e);
8585
}
@@ -100,7 +100,7 @@ public void idempotentLF() {
100100
try {
101101
String mangled = expected.replace(separator, "\n");
102102
String output = createFormatter().formatSource(mangled);
103-
assertThat(output).describedAs("bad output for " + name).isEqualTo(mangled);
103+
assertThat(output).describedAs("bad output for %s", name).isEqualTo(mangled);
104104
} catch (FormatterException e) {
105105
throw new RuntimeException(String.format("Formatter crashed on %s", name), e);
106106
}
@@ -113,7 +113,7 @@ public void idempotentCR() {
113113
try {
114114
String mangled = expected.replace(separator, "\r");
115115
String output = createFormatter().formatSource(mangled);
116-
assertThat(output).describedAs("bad output for " + name).isEqualTo(mangled);
116+
assertThat(output).describedAs("bad output for %s", name).isEqualTo(mangled);
117117
} catch (FormatterException e) {
118118
throw new RuntimeException(String.format("Formatter crashed on %s", name), e);
119119
}
@@ -126,7 +126,7 @@ public void idempotentCRLF() {
126126
try {
127127
String mangled = expected.replace(separator, "\r\n");
128128
String output = createFormatter().formatSource(mangled);
129-
assertThat(output).describedAs("bad output for " + name).isEqualTo(mangled);
129+
assertThat(output).describedAs("bad output for %s", name).isEqualTo(mangled);
130130
} catch (FormatterException e) {
131131
throw new RuntimeException(String.format("Formatter crashed on %s", name), e);
132132
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/JavaCommentsHelperTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void theMissingSpaceRuleAppliesToEveryLineOfTheRun() throws Exception {
102102
// over as one tok (23 and later) or as one tok per line.
103103
String rewritten = rewrite("///Summary line.\n" + " ".repeat(COLUMN) + "///More text.", Style.OJF);
104104

105-
assertThat(rewritten).isEqualTo("/// Summary line.\n" + " ".repeat(COLUMN) + "/// More text.");
105+
assertThat(rewritten).isEqualTo("/// Summary line.\n%s/// More text.", " ".repeat(COLUMN));
106106
}
107107

108108
@Test

0 commit comments

Comments
 (0)