Skip to content

Commit 11f51fe

Browse files
committed
Make RedundantStringConversion an error
Six toString() calls on what string concatenation or Path.of converts anyway are gone: on the diagnostics Main prints, on the paths MainTest expects, and on an environment variable, which is a String already.
1 parent 2ade9da commit 11f51fe

4 files changed

Lines changed: 6 additions & 9 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
@@ -28,6 +28,7 @@ tasks.withType(JavaCompile).configureEach {
2828
error('FormatStringConcatenation')
2929
error('JUnitClassModifiers')
3030
error('JUnitMethodDeclaration')
31+
error('RedundantStringConversion')
3132
error('RefactorSwitch')
3233
error('SameNameButDifferent')
3334
error('UnusedVariable')

‎open-java-format-jdk-bootstrap/src/test/java/com/palantir/javaformat/bootstrap/FormatterServicesTest.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ private static Stream<FormatterService> getFormatters() {
102102
return Stream.of(
103103
new BootstrappingFormatterService(
104104
javaBinPath(), Runtime.version().feature(), getClasspath()),
105-
new NativeImageFormatterService(
106-
Path.of(System.getenv("NATIVE_IMAGE_CLASSPATH").toString())));
105+
new NativeImageFormatterService(Path.of(System.getenv("NATIVE_IMAGE_CLASSPATH"))));
107106
}
108107

109108
private String getTestResourceContent(String resourceName) {

‎open-java-format/src/main/java/com/palantir/javaformat/java/Main.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private int formatFiles(
165165
} catch (ExecutionException e) {
166166
if (e.getCause() instanceof FormatterException) {
167167
for (FormatterDiagnostic diagnostic : ((FormatterException) e.getCause()).diagnostics()) {
168-
errWriter.println(path + ":" + diagnostic.toString());
168+
errWriter.println(path + ":" + diagnostic);
169169
}
170170
} else {
171171
errWriter.println(path + ": error: "
@@ -228,7 +228,7 @@ private int formatStdin(CommandLineOptions parameters, JavaFormatterOptions opti
228228
}
229229
} catch (FormatterException e) {
230230
for (FormatterDiagnostic diagnostic : e.diagnostics()) {
231-
errWriter.println(stdinFilename + ":" + diagnostic.toString());
231+
errWriter.println(stdinFilename + ":" + diagnostic);
232232
}
233233
ok = false;
234234
// TODO(cpovirk): Catch other types of exception (as we do in the formatFiles case).

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,7 @@ void dryRunFiles() throws Exception {
439439
assertThat(exitCode).isEqualTo(0);
440440

441441
assertThat(out.toString())
442-
.isEqualTo(b.toAbsolutePath().toString()
443-
+ System.lineSeparator()
444-
+ c.toAbsolutePath().toString()
445-
+ System.lineSeparator());
442+
.isEqualTo(b.toAbsolutePath() + System.lineSeparator() + c.toAbsolutePath() + System.lineSeparator());
446443
assertThat(err.toString()).isEmpty();
447444
}
448445

@@ -495,7 +492,7 @@ void exitIfChangedFiles() throws Exception {
495492
Process process = formatterMain(path.toAbsolutePath().toString()).start();
496493
process.waitFor();
497494
String out = new String(ByteStreams.toByteArray(process.getInputStream()), UTF_8);
498-
assertThat(out).isEqualTo(path.toAbsolutePath().toString() + System.lineSeparator());
495+
assertThat(out).isEqualTo(path.toAbsolutePath() + System.lineSeparator());
499496
assertThat(process.exitValue()).isEqualTo(1);
500497
}
501498

0 commit comments

Comments
 (0)