Skip to content

Commit 6bbe556

Browse files
committed
Deal with DirtyState.Calculation is gone.
1 parent c2fe9c6 commit 6bbe556

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ public static DirtyState of(Formatter formatter, File file) throws IOException {
7474
}
7575

7676
public static DirtyState of(Formatter formatter, File file, byte[] rawBytes) {
77-
String raw = new String(rawBytes, formatter.getEncoding());
77+
return of(formatter, file, rawBytes, new String(rawBytes, formatter.getEncoding()));
78+
}
79+
80+
public static DirtyState of(Formatter formatter, File file, byte[] rawBytes, String raw) {
81+
return of(formatter, file, rawBytes, raw, new ValuePerStep<>(formatter));
82+
}
83+
84+
public static DirtyState of(Formatter formatter, File file, byte[] rawBytes, String raw, ValuePerStep<Throwable> exceptionPerStep) {
7885
// check that all characters were encodable
7986
String encodingError = EncodingErrorMsg.msg(raw, rawBytes, formatter.getEncoding());
8087
if (encodingError != null) {
@@ -84,7 +91,7 @@ public static DirtyState of(Formatter formatter, File file, byte[] rawBytes) {
8491
String rawUnix = LineEnding.toUnix(raw);
8592

8693
// enforce the format
87-
String formattedUnix = formatter.compute(rawUnix, file);
94+
String formattedUnix = formatter.computeWithLint(rawUnix, file, exceptionPerStep);
8895
// convert the line endings if necessary
8996
String formatted = formatter.computeLineEndings(formattedUnix, file);
9097

@@ -95,13 +102,13 @@ public static DirtyState of(Formatter formatter, File file, byte[] rawBytes) {
95102
}
96103

97104
// F(input) != input, so we'll do a padded check
98-
String doubleFormattedUnix = formatter.compute(formattedUnix, file);
105+
String doubleFormattedUnix = formatter.computeWithLint(formattedUnix, file, exceptionPerStep);
99106
if (doubleFormattedUnix.equals(formattedUnix)) {
100107
// most dirty files are idempotent-dirty, so this is a quick-short circuit for that common case
101108
return new DirtyState(formattedBytes);
102109
}
103110

104-
PaddedCell cell = PaddedCell.check(formatter, file, rawUnix);
111+
PaddedCell cell = PaddedCell.check(formatter, file, rawUnix, exceptionPerStep);
105112
if (!cell.isResolvable()) {
106113
return didNotConverge;
107114
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ public static LintState of(Formatter formatter, File file) throws IOException {
9090

9191
public static LintState of(Formatter formatter, File file, byte[] rawBytes) {
9292
var exceptions = new ValuePerStep<Throwable>(formatter);
93-
var dirtyCalculation = DirtyState.of(formatter, file, rawBytes);
94-
var dirty = dirtyCalculation.calculateDirtyState(exceptions);
93+
var raw = new String(rawBytes, formatter.getEncoding());
94+
var dirty = DirtyState.of(formatter, file, rawBytes, raw, exceptions);
9595

96-
String toLint = LineEnding.toUnix(dirty.isClean() || dirty.didNotConverge() ? dirtyCalculation.raw : new String(dirty.canonicalBytes(), formatter.getEncoding()));
96+
String toLint = LineEnding.toUnix(dirty.isClean() || dirty.didNotConverge() ? raw : new String(dirty.canonicalBytes(), formatter.getEncoding()));
9797

9898
var lints = new ValuePerStep<List<Lint>>(formatter);
9999
// if a step did not throw an exception, then it gets to check for lints if it wants

0 commit comments

Comments
 (0)