Skip to content

Commit 5c42457

Browse files
committed
Restore the "legacy" error printing for both Formatter and DirtyState.
1 parent f3be100 commit 5c42457

File tree

7 files changed

+21
-24
lines changed

7 files changed

+21
-24
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ private Calculation(Formatter formatter, File file, byte[] rawBytes) {
101101
* due to diverging idempotence.
102102
*/
103103
public DirtyState calculateDirtyState() {
104-
return calculateDirtyState(new ValuePerStep<>(formatter));
104+
ValuePerStep<Throwable> exceptionPerStep = new ValuePerStep<>(formatter);
105+
DirtyState result = calculateDirtyState(exceptionPerStep);
106+
LintPolicy.legacyBehavior(formatter, file, exceptionPerStep);
107+
return result;
105108
}
106109

107110
/**

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,7 @@ public String computeLineEndings(String unix, File file) {
129129
public String compute(String unix, File file) {
130130
ValuePerStep<Throwable> exceptionPerStep = new ValuePerStep<>(this);
131131
String result = computeWithLint(unix, file, exceptionPerStep);
132-
for (int i = 0; i < steps.size(); ++i) {
133-
Throwable exception = exceptionPerStep.get(i);
134-
if (exception != null && exception != LintState.formatStepCausedNoChange()) {
135-
LintPolicy.error(exception, steps.get(i), file.getAbsolutePath());
136-
throw ThrowingEx.asRuntimeRethrowError(exception);
137-
}
138-
}
132+
LintPolicy.legacyBehavior(this, file, exceptionPerStep);
139133
return result;
140134
}
141135

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18+
import java.io.File;
19+
1820
import org.slf4j.Logger;
1921
import org.slf4j.LoggerFactory;
2022

@@ -28,4 +30,14 @@ static void error(Throwable e, FormatterStep step, String relativePath) {
2830
static void warning(Throwable e, FormatterStep step, String relativePath) {
2931
logger.warn("Unable to apply step '{}' to '{}'", step.getName(), relativePath, e);
3032
}
33+
34+
static void legacyBehavior(Formatter formatter, File file, ValuePerStep<Throwable> exceptionPerStep) {
35+
for (int i = 0; i < formatter.getSteps().size(); ++i) {
36+
Throwable exception = exceptionPerStep.get(i);
37+
if (exception != null && exception != LintState.formatStepCausedNoChange()) {
38+
LintPolicy.error(exception, formatter.getSteps().get(i), file.getName());
39+
throw ThrowingEx.asRuntimeRethrowError(exception);
40+
}
41+
}
42+
}
3143
}

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121

2222
import java.io.IOException;
2323

24-
import org.junit.jupiter.api.Disabled;
2524
import org.junit.jupiter.api.Test;
2625
import org.owasp.encoder.Encode;
2726

28-
import com.diffplug.spotless.tag.ForLintRefactor;
29-
3027
class BiomeIntegrationTest extends GradleIntegrationHarness {
3128
/**
3229
* Tests that biome can be used as a generic formatting step.
@@ -323,8 +320,6 @@ void failureWhenExeNotFound() throws Exception {
323320
* @throws Exception When a test failure occurs.
324321
*/
325322
@Test
326-
@Disabled
327-
@ForLintRefactor
328323
void failureWhenNotParseable() throws Exception {
329324
setFile("build.gradle").toLines(
330325
"plugins {",

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ErrorShouldRethrowTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import com.diffplug.spotless.tag.ForLintRefactor;
3333

3434
/** Tests the desired behavior from https://github.com/diffplug/spotless/issues/46. */
35-
@Disabled
36-
@ForLintRefactor
3735
class ErrorShouldRethrowTest extends GradleIntegrationHarness {
3836
private void writeBuild(String... toInsert) throws IOException {
3937
List<String> lines = new ArrayList<>();
@@ -86,6 +84,8 @@ void unlessEnforceCheckIsFalse() throws Exception {
8684
runWithSuccess("> Task :processResources NO-SOURCE");
8785
}
8886

87+
@Disabled
88+
@ForLintRefactor
8989
@Test
9090
void unlessExemptedByStep() throws Exception {
9191
writeBuild(
@@ -97,6 +97,8 @@ void unlessExemptedByStep() throws Exception {
9797
"Unable to apply step 'no swearing' to 'README.md'");
9898
}
9999

100+
@Disabled
101+
@ForLintRefactor
100102
@Test
101103
void unlessExemptedByPath() throws Exception {
102104
writeBuild(

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
import java.io.File;
2121
import java.io.IOException;
2222

23-
import org.junit.jupiter.api.Disabled;
2423
import org.junit.jupiter.api.Test;
2524

26-
import com.diffplug.spotless.tag.ForLintRefactor;
27-
2825
class KotlinExtensionTest extends GradleIntegrationHarness {
2926
private static final String HEADER = "// License Header";
3027
private static final String HEADER_WITH_YEAR = "// License Header $YEAR";
@@ -150,8 +147,6 @@ void testSetEditorConfigCanOverrideEditorConfigFile() throws IOException {
150147
}
151148

152149
@Test
153-
@Disabled
154-
@ForLintRefactor
155150
void withCustomRuleSetApply() throws IOException {
156151
setFile("build.gradle.kts").toLines(
157152
"plugins {",

plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
import static org.junit.jupiter.api.Assertions.assertTrue;
2121
import static org.owasp.encoder.Encode.forXml;
2222

23-
import org.junit.jupiter.api.Disabled;
2423
import org.junit.jupiter.api.Test;
2524

2625
import com.diffplug.spotless.maven.MavenIntegrationHarness;
27-
import com.diffplug.spotless.tag.ForLintRefactor;
2826

2927
class BiomeMavenTest extends MavenIntegrationHarness {
3028
/**
@@ -192,8 +190,6 @@ void failureWhenExeNotFound() throws Exception {
192190
* @throws Exception When a test failure occurs.
193191
*/
194192
@Test
195-
@Disabled
196-
@ForLintRefactor
197193
void failureWhenNotParseable() throws Exception {
198194
writePomWithBiomeSteps("**/*.js", "<biome><version>1.2.0</version><language>json</language></biome>");
199195
setFile("biome_test.js").toResource("biome/js/fileBefore.js");

0 commit comments

Comments
 (0)