Skip to content

Commit c9f52d5

Browse files
committed
Pipe linting through the core FormatterStep implementations.
1 parent 322d5bf commit c9f52d5

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616
package com.diffplug.spotless;
1717

1818
import java.io.File;
19+
import java.util.List;
1920
import java.util.Objects;
20-
import java.util.regex.Matcher;
2121
import java.util.regex.Pattern;
2222

2323
import javax.annotation.Nullable;
@@ -36,14 +36,24 @@ final class FilterByContentPatternFormatterStep extends DelegateFormatterStep {
3636
public @Nullable String format(String raw, File file) throws Exception {
3737
Objects.requireNonNull(raw, "raw");
3838
Objects.requireNonNull(file, "file");
39-
Matcher matcher = contentPattern.matcher(raw);
40-
if (matcher.find() == (onMatch == OnMatch.INCLUDE)) {
39+
if (contentPattern.matcher(raw).find() == (onMatch == OnMatch.INCLUDE)) {
4140
return delegateStep.format(raw, file);
4241
} else {
4342
return raw;
4443
}
4544
}
4645

46+
@Override
47+
public List<Lint> lint(String raw, File file) throws Exception {
48+
Objects.requireNonNull(raw, "raw");
49+
Objects.requireNonNull(file, "file");
50+
if (contentPattern.matcher(raw).find() == (onMatch == OnMatch.INCLUDE)) {
51+
return delegateStep.lint(raw, file);
52+
} else {
53+
return List.of();
54+
}
55+
}
56+
4757
@Override
4858
public boolean equals(Object o) {
4959
if (this == o) {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
package com.diffplug.spotless;
1717

1818
import java.io.File;
19+
import java.util.List;
1920
import java.util.Objects;
2021

2122
import javax.annotation.Nullable;
@@ -39,6 +40,17 @@ final class FilterByFileFormatterStep extends DelegateFormatterStep {
3940
}
4041
}
4142

43+
@Override
44+
public List<Lint> lint(String content, File file) throws Exception {
45+
Objects.requireNonNull(content, "content");
46+
Objects.requireNonNull(file, "file");
47+
if (filter.accept(file)) {
48+
return delegateStep.lint(content, file);
49+
} else {
50+
return List.of();
51+
}
52+
}
53+
4254
@Override
4355
public boolean equals(Object o) {
4456
if (this == o) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.io.Serializable;
2020
import java.util.Arrays;
21+
import java.util.List;
2122

2223
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2324

@@ -48,6 +49,14 @@ public String format(String rawUnix, File file) throws Exception {
4849
return formatter.apply(rawUnix, file);
4950
}
5051

52+
@Override
53+
public List<Lint> lint(String content, File file) throws Exception {
54+
if (formatter == null) {
55+
formatter = stateToFormatter(state());
56+
}
57+
return formatter.lint(content, file);
58+
}
59+
5160
@Override
5261
public boolean equals(Object o) {
5362
if (o == null) {

0 commit comments

Comments
 (0)