Skip to content

Commit

Permalink
ScalaFmt takes filepath into consideration.
Browse files Browse the repository at this point in the history
fix formatting.
  • Loading branch information
SimY4 committed May 23, 2024
1 parent 04d5f28 commit 30924e4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 DiffPlug
* Copyright 2022-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,4 +51,9 @@ public ScalafmtFormatterFunc(FileSignature configSignature) throws Exception {
public String apply(String input) {
return Scalafmt.format(input, config, Set$.MODULE$.empty()).get();
}

@Override
public String apply(String input, File file) {
return Scalafmt.format(input, config, Set$.MODULE$.empty(), file.getAbsolutePath()).get();
}
}
6 changes: 5 additions & 1 deletion testlib/src/main/java/com/diffplug/spotless/StepHarness.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public StepHarness testUnaffected(String idempotentElement) {
public StepHarness testResource(String resourceBefore, String resourceAfter) {
String before = ResourceHarness.getTestResource(resourceBefore);
String after = ResourceHarness.getTestResource(resourceAfter);
return test(before, after);
String actual = formatter.compute(LineEnding.toUnix(before), new File(resourceBefore));
assertEquals(after, actual, "Step application failed");
actual = formatter.compute(LineEnding.toUnix(after), new File(resourceAfter));
assertEquals(after, actual, "Step is not idempotent");
return this;
}

/** Asserts that the given elements in the resources directory are transformed as expected. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version = 3.7.3
runner.dialect = scala213
style = defaultWithAlign # For pretty alignment.
maxColumn = 200 # For my mega-wide display
fileOverride {
"glob:**/scala/scalafmt/**" {
maxColumn = 20 # For my teensy narrow display
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,13 @@ void behaviorCustomConfig() {
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
}

@Test
void behaviorFileOverride() {
FormatterStep step = ScalaFmtStep.create(ScalaFmtStep.DEFAULT_VERSION, TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.fileoverride.conf"));
StepHarness.forStep(step)
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
}

@Test
void behaviorDefaultConfigVersion_3_0_0() {
FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null);
Expand Down

0 comments on commit 30924e4

Please sign in to comment.