Skip to content

Commit f63d909

Browse files
committed
Prettier's configuration now roundtrips without any problem.
1 parent a6e711d commit f63d909

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

lib/src/main/java/com/diffplug/spotless/npm/PrettierConfig.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 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,44 +16,30 @@
1616
package com.diffplug.spotless.npm;
1717

1818
import java.io.File;
19-
import java.io.IOException;
2019
import java.io.Serializable;
2120
import java.util.Map;
2221
import java.util.TreeMap;
2322

2423
import javax.annotation.Nullable;
2524

2625
import com.diffplug.spotless.FileSignature;
27-
import com.diffplug.spotless.ThrowingEx;
28-
29-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3026

3127
public class PrettierConfig implements Serializable {
3228

3329
private static final long serialVersionUID = -8709340269833126583L;
3430

35-
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
36-
@Nullable
37-
private final transient File prettierConfigPath;
38-
39-
@SuppressWarnings("unused")
40-
private final FileSignature prettierConfigPathSignature;
31+
private final FileSignature.Promised prettierConfigPathSignature;
4132

4233
private final TreeMap<String, Object> options;
4334

4435
public PrettierConfig(@Nullable File prettierConfigPath, @Nullable Map<String, Object> options) {
45-
try {
46-
this.prettierConfigPath = prettierConfigPath;
47-
this.prettierConfigPathSignature = prettierConfigPath != null ? FileSignature.signAsList(this.prettierConfigPath) : FileSignature.signAsList();
48-
this.options = options == null ? new TreeMap<>() : new TreeMap<>(options);
49-
} catch (IOException e) {
50-
throw ThrowingEx.asRuntime(e);
51-
}
36+
this.prettierConfigPathSignature = prettierConfigPath == null ? null : FileSignature.promise(prettierConfigPath);
37+
this.options = options == null ? new TreeMap<>() : new TreeMap<>(options);
5238
}
5339

5440
@Nullable
5541
public File getPrettierConfigPath() {
56-
return prettierConfigPath;
42+
return prettierConfigPathSignature == null ? null : prettierConfigPathSignature.get().getOnlyFile();
5743
}
5844

5945
public Map<String, Object> getOptions() {

testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.util.Collections;
2020
import java.util.Map;
2121

22+
import com.diffplug.spotless.SerializableEqualityTester;
23+
import com.diffplug.spotless.java.GoogleJavaFormatStep;
24+
2225
import org.junit.jupiter.api.Nested;
2326
import org.junit.jupiter.api.Test;
2427
import org.junit.jupiter.params.ParameterizedTest;
@@ -189,4 +192,32 @@ private String major(String semVer) {
189192
return semVer.split("\\.")[0];
190193
}
191194
}
195+
196+
@Test
197+
void equality() {
198+
new SerializableEqualityTester() {
199+
String groupArtifact = GoogleJavaFormatStep.defaultGroupArtifact();
200+
String version = "1.11.0";
201+
String style = "";
202+
boolean reflowLongStrings = false;
203+
204+
@Override
205+
protected void setupTest(API api) {
206+
// same version == same
207+
api.areDifferentThan();
208+
// change the groupArtifact, and it's different
209+
groupArtifact = "io.opil:google-java-format";
210+
api.areDifferentThan();
211+
}
212+
213+
@Override
214+
protected FormatterStep create() {
215+
return PrettierFormatterStep.create(Map.of(), TestProvisioner.mavenCentral(), projectDir(),
216+
buildDir(),
217+
null,
218+
npmPathResolver(),
219+
);
220+
}
221+
}.testEquals();
222+
}
192223
}

0 commit comments

Comments
 (0)