Skip to content

Commit df26a83

Browse files
authored
ScalaFmt takes filepath into consideration. (#1854)
2 parents 4c06539 + 1bea53f commit df26a83

File tree

8 files changed

+40
-17
lines changed

8 files changed

+40
-17
lines changed

CHANGES.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1313
### Added
1414
* `FileSignature.Promised` and `JarState.Promised` to facilitate round-trip serialization for the Gradle configuration cache. ([#1945](https://github.com/diffplug/spotless/pull/1945))
1515
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
16+
### Fixed
17+
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
18+
* Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052))
19+
* Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096))
20+
* scalafmt.conf fileOverride section now works correctly ([#1854](https://github.com/diffplug/spotless/pull/1854))
1621
### Changes
1722
* Bump default `ktfmt` version to latest `0.46` -> `0.47`. ([#2045](https://github.com/diffplug/spotless/pull/2045))
1823
* Bump default `sortpom` version to latest `3.2.1` -> `3.4.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049))
@@ -23,10 +28,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2328
### Removed
2429
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
2530
* **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954))
26-
### Fixed
27-
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
28-
* Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052))
29-
* Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096))
3031

3132
## [2.45.0] - 2024-01-23
3233
### Added

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 DiffPlug
2+
* Copyright 2022-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.
@@ -29,7 +29,7 @@
2929

3030
import scala.collection.immutable.Set$;
3131

32-
public class ScalafmtFormatterFunc implements FormatterFunc {
32+
public class ScalafmtFormatterFunc implements FormatterFunc.NeedsFile {
3333
private final ScalafmtConfig config;
3434

3535
public ScalafmtFormatterFunc(FileSignature configSignature) throws Exception {
@@ -48,7 +48,7 @@ public ScalafmtFormatterFunc(FileSignature configSignature) throws Exception {
4848
}
4949

5050
@Override
51-
public String apply(String input) {
52-
return Scalafmt.format(input, config, Set$.MODULE$.empty()).get();
51+
public String applyWithFile(String unix, File file) throws Exception {
52+
return Scalafmt.format(unix, config, Set$.MODULE$.empty(), file.getAbsolutePath()).get();
5353
}
5454
}

plugin-gradle/CHANGES.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Added
7+
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
8+
* Add support for formatting and sorting Maven POMs ([#2082](https://github.com/diffplug/spotless/issues/2082))
69
### Fixed
710
* Full no-asterisk support for configuration cache ([#2088](https://github.com/diffplug/spotless/pull/2088) closes [#1274](https://github.com/diffplug/spotless/issues/1274) and [#987](https://github.com/diffplug/spotless/issues/987)).
811
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
912
* Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052))
1013
* Fixed memory leak introduced in 6.21.0 ([#2067](https://github.com/diffplug/spotless/issues/2067))
1114
* Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096))
15+
* scalafmt.conf fileOverride section now works correctly ([#1854](https://github.com/diffplug/spotless/pull/1854))
1216
### Changes
1317
* Bump default `ktfmt` version to latest `0.46` -> `0.47`. ([#2045](https://github.com/diffplug/spotless/pull/2045))
1418
* Bump default `sortpom` version to latest `3.2.1` -> `3.4.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049))
1519
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
1620
* Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057))
1721
* Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078))
1822
* Bump default `sortpom` version to latest `3.4.1` -> `4.0.0` and support versions back to `3.2.1`. ([#2115](https://github.com/diffplug/spotless/pull/2115))
19-
### Added
20-
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
21-
* Add support for formatting and sorting Maven POMs ([#2082](https://github.com/diffplug/spotless/issues/2082))
2223

2324
## [6.25.0] - 2024-01-23
2425
### Added

plugin-maven/CHANGES.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
44

55
## [Unreleased]
6+
### Added
7+
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
8+
* Skip execution in M2E (incremental) builds by default ([#1814](https://github.com/diffplug/spotless/issues/1814), [#2037](https://github.com/diffplug/spotless/issues/2037))
69
### Fixed
710
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
811
* Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052))
912
* Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096))
13+
* scalafmt.conf fileOverride section now works correctly ([#1854](https://github.com/diffplug/spotless/pull/1854))
1014
### Changes
1115
* Bump default `ktfmt` version to latest `0.46` -> `0.47`. ([#2045](https://github.com/diffplug/spotless/pull/2045))
1216
* Bump default `sortpom` version to latest `3.2.1` -> `3.4.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049))
1317
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
1418
* Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057))
1519
* Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078))
1620
* Bump default `sortpom` version to latest `3.4.1` -> `4.0.0` and support versions back to `3.2.1`. ([#2115](https://github.com/diffplug/spotless/pull/2115))
17-
### Added
18-
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
19-
* Skip execution in M2E (incremental) builds by default ([#1814](https://github.com/diffplug/spotless/issues/1814), [#2037](https://github.com/diffplug/spotless/issues/2037))
2021

2122
## [2.43.0] - 2024-01-23
2223
### Added

testlib/src/main/java/com/diffplug/spotless/StepHarness.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ public StepHarness testUnaffected(String idempotentElement) {
8080
public StepHarness testResource(String resourceBefore, String resourceAfter) {
8181
String before = ResourceHarness.getTestResource(resourceBefore);
8282
String after = ResourceHarness.getTestResource(resourceAfter);
83-
return test(before, after);
83+
String actual = formatter().compute(LineEnding.toUnix(before), new File(resourceBefore));
84+
assertEquals(after, actual, "Step application failed");
85+
actual = formatter().compute(LineEnding.toUnix(after), new File(resourceAfter));
86+
assertEquals(after, actual, "Step is not idempotent");
87+
return this;
8488
}
8589

8690
/** Asserts that the given elements in the resources directory are transformed as expected. */

testlib/src/main/resources/scala/scalafmt/basic.dirty

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@ foobar("annot", {
1+
@foobar ("annot", {
22
val x = 2
33
val y = 2 // y=2
44
x + y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version = 3.7.3
2+
runner.dialect = scala213
3+
style = defaultWithAlign # For pretty alignment.
4+
maxColumn = 200 # For my mega-wide display
5+
fileOverride {
6+
"glob:**/scala/scalafmt/**" {
7+
maxColumn = 20 # For my teensy narrow display
8+
}
9+
}

testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 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.
@@ -40,6 +40,13 @@ void behaviorCustomConfig() {
4040
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
4141
}
4242

43+
@Test
44+
void behaviorFileOverride() {
45+
FormatterStep step = ScalaFmtStep.create(ScalaFmtStep.DEFAULT_VERSION, TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.fileoverride.conf"));
46+
StepHarness.forStep(step)
47+
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
48+
}
49+
4350
@Test
4451
void behaviorDefaultConfigVersion_3_0_0() {
4552
FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null);

0 commit comments

Comments
 (0)