Skip to content

Commit 6a734f6

Browse files
committed
Slightly better error messages for ReplaceRegexStep.
1 parent 1098702 commit 6a734f6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ public List<Lint> lint(String raw, File file) {
9090
var matcher = regex.matcher(raw);
9191
while (matcher.find()) {
9292
int line = 1 + (int) raw.codePoints().limit(matcher.start()).filter(c -> c == '\n').count();
93-
lints.add(Lint.atLine(line, matcher.group(0), lintDetail));
93+
String errorCode = matcher.group(0).trim();
94+
int firstNewline = errorCode.indexOf("\n");
95+
if (firstNewline != -1) {
96+
errorCode = errorCode.substring(0, firstNewline);
97+
}
98+
lints.add(Lint.atLine(line, errorCode, lintDetail));
9499
}
95100
return lints;
96101
}

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,11 @@ void testRemoveWildcardImports() throws Exception {
3131
setFile(path).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test");
3232
expectSelfieErrorMsg(mavenRunner().withArguments("spotless:apply").runHasError()).toBe("""
3333
Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:VERSION:apply (default-cli) on project spotless-maven-plugin-tests: There were 5 lint error(s), they must be fixed or suppressed.
34-
src/main/java/test.java:L1 removeWildcardImports(import java.util.*;
35-
) 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
36-
src/main/java/test.java:L2 removeWildcardImports(import static java.util.Collections.*;
37-
) 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
38-
src/main/java/test.java:L5 removeWildcardImports(import io.quarkus.maven.dependency.*;
39-
) 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
40-
src/main/java/test.java:L6 removeWildcardImports(import static io.quarkus.vertx.web.Route.HttpMethod.*;
41-
) 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
42-
src/main/java/test.java:L7 removeWildcardImports(import static org.springframework.web.reactive.function.BodyInserters.*;
43-
) 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
34+
src/main/java/test.java:L1 removeWildcardImports(import java.util.*;) 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
35+
src/main/java/test.java:L2 removeWildcardImports(import static java.util.Collections.*;) 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
36+
src/main/java/test.java:L5 removeWildcardImports(import io.quarkus.maven.dependency.*;) 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
37+
src/main/java/test.java:L6 removeWildcardImports(import static io.quarkus.vertx.web.Route.HttpMethod.*;) 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
38+
src/main/java/test.java:L7 removeWildcardImports(import static org.springframework.web.reactive.function.BodyInserters.*;) 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
4439
Resolve these lints or suppress with `<lintSuppressions>`
4540
""");
4641
assertFile(path).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test");

0 commit comments

Comments
 (0)