Skip to content

Commit 31302c8

Browse files
committed
Improve error messages.
1 parent a83807f commit 31302c8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ 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, ruleId, lintDetail));
93+
lints.add(Lint.atLine(line, matcher.group(0), lintDetail));
9494
}
9595
return lints;
9696
}

testlib/src/test/java/com/diffplug/spotless/generic/ReplaceRegexStepTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ void formatter() throws Exception {
3131

3232
@Test
3333
void lint() throws Exception {
34-
FormatterStep step = ReplaceRegexStep.lint("regex", "bad", "no bad words");
34+
FormatterStep step = ReplaceRegexStep.lint("stayPositive", "(bad|awful)", "no negative words");
3535
StepHarness.forStep(step)
3636
.expectLintsOf(StringPrinter.buildStringFromLines(
3737
"bad",
38-
"x bad y",
39-
"ok"))
40-
.toBe("L1 regex(bad) no bad words\nL2 regex(bad) no bad words");
38+
"oh boy",
39+
"x awful y",
40+
"yippeee"))
41+
.toBe("L1 stayPositive(bad) no negative words",
42+
"L3 stayPositive(awful) no negative words");
4143
}
4244
}

0 commit comments

Comments
 (0)