Skip to content

Commit

Permalink
Added scalafmt 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Simkin committed Aug 19, 2021
1 parent 2ade60a commit 646a598
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ public class ScalaFmtStep {
private ScalaFmtStep() {}

private static final Pattern VERSION_PRE_2_0 = Pattern.compile("[10]\\.(\\d+)\\.\\d+");
private static final Pattern VERSION_PRE_3_0 = Pattern.compile("2\\.(\\d+)\\.\\d+");
private static final String DEFAULT_VERSION = "2.0.1";
static final String NAME = "scalafmt";
static final String MAVEN_COORDINATE_PRE_2_0 = "com.geirsson:scalafmt-core_2.11:";
static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_2.11:";
static final String MAVEN_COORDINATE_PRE_3_0 = "org.scalameta:scalafmt-core_2.11:";
static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_2.13:";

public static FormatterStep create(Provisioner provisioner) {
return create(defaultVersion(), provisioner, null);
Expand All @@ -69,9 +71,11 @@ static final class State implements Serializable {

State(String version, Provisioner provisioner, @Nullable File configFile) throws IOException {
String mavenCoordinate;
Matcher versionMatcher = VERSION_PRE_2_0.matcher(version);
if (versionMatcher.matches()) {
Matcher versionMatcher;
if ((versionMatcher = VERSION_PRE_2_0.matcher()).matches()) {
mavenCoordinate = MAVEN_COORDINATE_PRE_2_0;
} else if ((versionMatcher = VERSION_PRE_3_0.matcher()).matches()) {
mavenCoordinate = MAVEN_COORDINATE_PRE_3_0;
} else {
mavenCoordinate = MAVEN_COORDINATE;
}
Expand Down

0 comments on commit 646a598

Please sign in to comment.