Skip to content

Commit e13b9b0

Browse files
committed
Fix lint
1 parent 350b8a4 commit e13b9b0

File tree

4 files changed

+11
-22
lines changed

4 files changed

+11
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public ShortcutException(Lint... lints) {
9191
private final List<Lint> lints;
9292

9393
ShortcutException(Collection<Lint> lints) {
94-
super(lints.iterator().next().detail);
94+
super(lints.iterator().next().toString());
9595
this.lints = List.copyOf(lints);
9696
}
9797

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ FormatterFunc toFormatter() {
6464

6565
FormatterFunc toLinter() {
6666
return raw -> {
67-
if (regex.matcher(raw).find()) {
68-
throw atLine(11111,"", replacement).shortcut();
67+
var matcher = regex.matcher(raw);
68+
if (matcher.find()) {
69+
int line = 1 + (int) raw.codePoints().limit(matcher.start()).filter(c -> c == '\n').count();
70+
throw atLine(line, matcher.group(0), replacement).shortcut();
6971
}
7072
return raw;
7173
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void removeWildCardImports() throws IOException {
9797
"}");
9898

9999
setFile("test.java").toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test");
100-
gradleRunner().withArguments("spotlessApply").build();
100+
gradleRunner().withArguments("spotlessApply").buildAndFail();
101101
assertFile("test.java").sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test");
102102
}
103103

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@
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;
2720
import org.junit.jupiter.api.BeforeEach;
2821
import org.junit.jupiter.api.Test;
2922

3023
import com.diffplug.spotless.maven.MavenIntegrationHarness;
3124

3225
class RemoveWildcardImportsStepTest extends MavenIntegrationHarness {
3326

34-
private static final String ERROR = "Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this";
27+
private static final String ERROR =
28+
"L1: (import java.util.*;\n" +
29+
") Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this";
3530

3631
@BeforeEach
3732
void init() throws Exception {
@@ -42,16 +37,8 @@ void init() throws Exception {
4237
void testRemoveWildcardImports() throws Exception {
4338
setFile(PATH).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test");
4439
assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test");
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");
40+
assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8())
41+
.contains(ERROR);
5542
}
5643

5744
@Test

0 commit comments

Comments
 (0)