Skip to content

Commit 0956a48

Browse files
author
Vincent Potucek
committed
removeWildcardImports: throw new AssertionError instead of removing
1 parent 777f496 commit 0956a48

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.diffplug.spotless.generic;
1717

18+
import static com.diffplug.spotless.Lint.atLine;
1819
import static com.diffplug.spotless.Lint.atUndefinedLine;
1920

2021
import java.io.Serializable;
@@ -64,7 +65,7 @@ FormatterFunc toFormatter() {
6465
FormatterFunc toLinter() {
6566
return raw -> {
6667
if (regex.matcher(raw).find()) {
67-
throw atUndefinedLine("", replacement).shortcut();
68+
throw atLine(11111,"", replacement).shortcut();
6869
}
6970
return raw;
7071
};

plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919

20+
import com.diffplug.spotless.FormatterStep;
21+
22+
import com.diffplug.spotless.StepHarnessWithFile;
23+
import com.diffplug.spotless.TestProvisioner;
24+
import com.diffplug.spotless.kotlin.KtLintStep;
25+
26+
import org.assertj.core.api.AbstractStringAssert;
2027
import org.junit.jupiter.api.BeforeEach;
2128
import org.junit.jupiter.api.Test;
2229

@@ -35,7 +42,16 @@ void init() throws Exception {
3542
void testRemoveWildcardImports() throws Exception {
3643
setFile(PATH).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test");
3744
assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test");
38-
assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()).contains(ERROR);
45+
AbstractStringAssert<?> abstractStringAssert = assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8());
46+
abstractStringAssert
47+
.contains(ERROR)
48+
// .contains("11111")
49+
;
50+
51+
FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral());
52+
StepHarnessWithFile.forStep(this, step)
53+
.testResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test", "java/removewildcardimports/JavaCodeWildcardsFormatted.test")
54+
.expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(standard:no-wildcard-imports) Wildcard import");
3955
}
4056

4157
@Test

0 commit comments

Comments
 (0)