Skip to content

Commit 16c1cde

Browse files
committed
(make multiline lints snapshot onto one line)
1 parent 5e21a11 commit 16c1cde

File tree

6 files changed

+28
-73
lines changed

6 files changed

+28
-73
lines changed

lib/src/main/java/com/diffplug/spotless/LintState.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@ public Map<FormatterStep, List<Lint>> getLints(Formatter formatter) {
6262
return result;
6363
}
6464

65-
public String asString(File file, Formatter formatter) {
65+
public String asStringDetailed(File file, Formatter formatter) {
66+
return asString(file, formatter, false);
67+
}
68+
69+
public String asStringOneLine(File file, Formatter formatter) {
70+
return asString(file, formatter, true);
71+
}
72+
73+
private String asString(File file, Formatter formatter, boolean oneLine) {
6674
if (!isHasLints()) {
6775
return "(none)";
6876
} else {
@@ -84,7 +92,16 @@ public String asString(File file, Formatter formatter) {
8492
}
8593
result.append(" ");
8694
result.append(step.getName()).append("(").append(lint.getRuleId()).append(") ");
87-
result.append(lint.getDetail());
95+
96+
int firstNewline = lint.getDetail().indexOf('\n');
97+
if (firstNewline == -1) {
98+
result.append(lint.getDetail());
99+
} else if (oneLine) {
100+
result.append(lint.getDetail(), 0, firstNewline);
101+
result.append(" (...)");
102+
} else {
103+
result.append(lint.getDetail());
104+
}
88105
result.append("\n");
89106
}
90107
}

testlib/src/main/java/com/diffplug/spotless/StepHarness.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public StringSelfie expectLintsOf(String before) {
9898
}
9999

100100
static StringSelfie expectLintsOf(LintState state, Formatter formatter) {
101-
String assertAgainst = state.asString(Formatter.NO_FILE_SENTINEL, formatter);
101+
String assertAgainst = state.asStringOneLine(Formatter.NO_FILE_SENTINEL, formatter);
102102
String cleaned = assertAgainst.replace("NO_FILE_SENTINEL:", "");
103103

104104
int numLines = 1;

testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ void versionBelowMinimumRequiredVersionIsNotAllowed() throws Exception {
6666
FormatterStep step = GoogleJavaFormatStep.create("1.2", "AOSP", TestProvisioner.mavenCentral());
6767
StepHarness.forStepNoRoundtrip(step)
6868
.expectLintsOfResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test")
69-
.toBe("LINE_UNDEFINED google-java-format(jvm-version) You are running Spotless on JVM 21. This requires google-java-format of at least 1.17.0 (you are using 1.2).",
70-
"");
69+
.toBe("LINE_UNDEFINED google-java-format(jvm-version) You are running Spotless on JVM 21. This requires google-java-format of at least 1.17.0 (you are using 1.2). (...)");
7170
}
7271

7372
@Test
@@ -76,8 +75,7 @@ void versionBelowOneDotTenIsNotAllowed() throws Exception {
7675
FormatterStep step = GoogleJavaFormatStep.create("1.9", "AOSP", TestProvisioner.mavenCentral());
7776
StepHarness.forStepNoRoundtrip(step)
7877
.expectLintsOfResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test")
79-
.toBe("LINE_UNDEFINED google-java-format(jvm-version) You are running Spotless on JVM 21. This requires google-java-format of at least 1.17.0 (you are using 1.9).",
80-
"");
78+
.toBe("LINE_UNDEFINED google-java-format(jvm-version) You are running Spotless on JVM 21. This requires google-java-format of at least 1.17.0 (you are using 1.9). (...)");
8179
}
8280

8381
@Test

testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,13 @@ void handlesObjectWithNull() {
7373

7474
@Test
7575
void handlesInvalidJson() {
76-
stepHarness.expectLintsOfResource("json/invalidJsonBefore.json").toBe("L3 jsonSimple(java.lang.IllegalArgumentException) Unable to format JSON",
77-
"\tat com.diffplug.spotless.json.JsonSimpleStep$State.format(JsonSimpleStep.java:109)",
78-
"\tat com.diffplug.spotless.json.JsonSimpleStep$State.lambda$toFormatter$0(JsonSimpleStep.java:94)",
79-
"\tat com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)",
80-
"\tat com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)",
81-
"\tat com.diffplug.spotless.LintState.of(LintState.java:141)",
82-
"\tat com.diffplug.spotless.StepHarness.expectLintsOf(StepHarness.java:96)",
83-
"\tat com.diffplug.spotless.StepHarness.expectLintsOfResource(StepHarness.java:92)",
84-
"\tat com.diffplug.spotless.json.JsonSimpleStepTest.handlesInvalidJson(JsonSimpleStepTest.java:76)",
85-
"\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)",
86-
"(... and more)");
76+
stepHarness.expectLintsOfResource("json/invalidJsonBefore.json").toBe("L3 jsonSimple(java.lang.IllegalArgumentException) Unable to format JSON (...)");
8777
}
8878

8979
@Test
9080
void handlesNotJson() {
9181
stepHarness.expectLintsOfResource("json/notJsonBefore.json")
92-
.toBe("LINE_UNDEFINED jsonSimple(java.lang.IllegalArgumentException) Unable to determine JSON type, expected a '{' or '[' but found '#'",
93-
"\tat com.diffplug.spotless.json.JsonSimpleStep$State.lambda$toFormatter$0(JsonSimpleStep.java:100)",
94-
"\tat com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)",
95-
"\tat com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)",
96-
"\tat com.diffplug.spotless.LintState.of(LintState.java:141)",
97-
"\tat com.diffplug.spotless.StepHarness.expectLintsOf(StepHarness.java:96)",
98-
"\tat com.diffplug.spotless.StepHarness.expectLintsOfResource(StepHarness.java:92)",
99-
"\tat com.diffplug.spotless.json.JsonSimpleStepTest.handlesNotJson(JsonSimpleStepTest.java:91)",
100-
"\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)",
101-
"\tat java.base/java.lang.reflect.Method.invoke(Method.java:580)",
102-
"(... and more)");
82+
.toBe("LINE_UNDEFINED jsonSimple(java.lang.IllegalArgumentException) Unable to determine JSON type, expected a '{' or '[' but found '#' (...)");
10383
}
10484

10585
@Test

testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,12 @@ void handlesObjectWithNull() {
3939

4040
@Test
4141
void handlesInvalidJson() {
42-
getStepHarness().expectLintsOfResource("json/invalidJsonBefore.json").toBe("L3 gson(com.google.gson.JsonSyntaxException) java.io.EOFException: End of input at line 3 column 1 path $.a",
43-
"\tat com.google.gson.Gson.fromJson(Gson.java:1370)",
44-
"\tat com.google.gson.Gson.fromJson(Gson.java:1262)",
45-
"\tat com.google.gson.Gson.fromJson(Gson.java:1171)",
46-
"\tat com.google.gson.Gson.fromJson(Gson.java:1107)",
47-
"\tat com.diffplug.spotless.glue.gson.GsonFormatterFunc.apply(GsonFormatterFunc.java:57)",
48-
"\tat com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)",
49-
"\tat com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)",
50-
"\tat com.diffplug.spotless.LintState.of(LintState.java:141)",
51-
"\tat com.diffplug.spotless.StepHarness.expectLintsOf(StepHarness.java:96)",
52-
"(... and more)");
42+
getStepHarness().expectLintsOfResource("json/invalidJsonBefore.json").toBe("L3 gson(com.google.gson.JsonSyntaxException) java.io.EOFException: End of input at line 3 column 1 path $.a (...)");
5343
}
5444

5545
@Test
5646
void handlesNotJson() {
57-
getStepHarness().expectLintsOfResource("json/notJsonBefore.json").toBe("LINE_UNDEFINED gson(java.lang.IllegalArgumentException) Unable to parse JSON",
58-
"\tat com.diffplug.spotless.glue.gson.GsonFormatterFunc.apply(GsonFormatterFunc.java:59)",
59-
"\tat com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)",
60-
"\tat com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)",
61-
"\tat com.diffplug.spotless.LintState.of(LintState.java:141)",
62-
"\tat com.diffplug.spotless.StepHarness.expectLintsOf(StepHarness.java:96)",
63-
"\tat com.diffplug.spotless.StepHarness.expectLintsOfResource(StepHarness.java:92)",
64-
"\tat com.diffplug.spotless.json.gson.GsonStepTest.handlesNotJson(GsonStepTest.java:57)",
65-
"\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)",
66-
"\tat java.base/java.lang.reflect.Method.invoke(Method.java:580)",
67-
"(... and more)");
47+
getStepHarness().expectLintsOfResource("json/notJsonBefore.json").toBe("LINE_UNDEFINED gson(java.lang.IllegalArgumentException) Unable to parse JSON (...)");
6848
}
6949

7050
@Test
@@ -97,17 +77,7 @@ void writesRawHtmlWhenHtmlEscapeDisabled() {
9777
@Test
9878
void handlesVersionIncompatibility() {
9979
StepHarness.forStep(GsonStep.create(new GsonConfig(false, false, INDENT, "1.7"), TestProvisioner.mavenCentral()))
100-
.expectLintsOf("").toBe("LINE_UNDEFINED gson(java.lang.IllegalStateException) There was a problem interacting with Gson; maybe you set an incompatible version?",
101-
"\tat com.diffplug.spotless.json.gson.GsonStep$State.toFormatter(GsonStep.java:73)",
102-
"\tat com.diffplug.spotless.FormatterStepSerializationRoundtrip.stateToFormatter(FormatterStepSerializationRoundtrip.java:64)",
103-
"\tat com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:47)",
104-
"\tat com.diffplug.spotless.LintState.of(LintState.java:141)",
105-
"\tat com.diffplug.spotless.StepHarness.expectLintsOf(StepHarness.java:96)",
106-
"\tat com.diffplug.spotless.json.gson.GsonStepTest.handlesVersionIncompatibility(GsonStepTest.java:100)",
107-
"\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)",
108-
"\tat java.base/java.lang.reflect.Method.invoke(Method.java:580)",
109-
"\tat org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:766)",
110-
"(... and more)");
80+
.expectLintsOf("").toBe("LINE_UNDEFINED gson(java.lang.IllegalStateException) There was a problem interacting with Gson; maybe you set an incompatible version? (...)");
11181
}
11282

11383
@Override

testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception {
137137
new PrettierConfig(null, ImmutableMap.of("parser", "postcss")));
138138
try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) {
139139
stepHarness.expectLintsOfResource("npm/prettier/filetypes/scss/scss.dirty")
140-
.toBe("1-35 prettier-format(prettier-format) com.diffplug.spotless.npm.SimpleRestClient$SimpleRestResponseException: Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")",
141-
"\tat com.diffplug.spotless.npm.SimpleRestClient.postJson(SimpleRestClient.java:72)",
142-
"\tat com.diffplug.spotless.npm.SimpleRestClient.postJson(SimpleRestClient.java:46)",
143-
"\tat com.diffplug.spotless.npm.PrettierRestService.format(PrettierRestService.java:46)",
144-
"\tat com.diffplug.spotless.npm.PrettierFormatterStep$PrettierFilePathPassingFormatterFunc.applyWithFile(PrettierFormatterStep.java:125)",
145-
"\tat com.diffplug.spotless.FormatterFunc$NeedsFile.apply(FormatterFunc.java:174)",
146-
"\tat com.diffplug.spotless.FormatterFunc$Closeable$1.apply(FormatterFunc.java:73)",
147-
"\tat com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)",
148-
"\tat com.diffplug.spotless.LintState.of(LintState.java:135)",
149-
"\tat com.diffplug.spotless.LintState.of(LintState.java:92)",
150-
"(... and more)");
140+
.toBe("LINE_UNDEFINED prettier-format(com.diffplug.spotless.npm.SimpleRestClient$SimpleRestResponseException) Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\") (...)");
151141
}
152142
}
153143
}

0 commit comments

Comments
 (0)