Skip to content

Commit 1313c4d

Browse files
committed
✨ feat(scalafmt): enforce version consistency in library and config file (fix #2460)
fix #2460
1 parent 688b9f5 commit 1313c4d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.nio.file.Files;
2222

2323
import org.scalafmt.Scalafmt;
24+
import org.scalafmt.Versions;
2425
import org.scalafmt.config.ScalafmtConfig;
2526
import org.scalafmt.config.ScalafmtConfig$;
2627

@@ -45,6 +46,16 @@ public ScalafmtFormatterFunc(FileSignature configSignature) throws Exception {
4546
String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
4647
config = Scalafmt.parseHoconConfig(configStr).get();
4748
}
49+
50+
// This check is to raise awareness to the user that the version of the config file is currently not used.
51+
// Context: https://github.com/diffplug/spotless/issues/2460
52+
// This check should be removed when Spotless dynamically loads the proper version of the Scalafmt library.
53+
String scalafmtLibraryVersion = Versions.version();
54+
if (!config.version().equals(scalafmtLibraryVersion)) {
55+
throw new IllegalArgumentException(
56+
"Spotless is using " + scalafmtLibraryVersion + " but the config file declares " + config.version() +
57+
". Both must match. Update the version declared in the plugin's settings and/or the config file.");
58+
}
4859
}
4960

5061
@Override

0 commit comments

Comments
 (0)