Skip to content

Commit 5c48ea8

Browse files
committed
Merge branch 'main' into fix-space-before-separator-jackson
2 parents 325897a + a8b5587 commit 5c48ea8

File tree

19 files changed

+226
-90
lines changed

19 files changed

+226
-90
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1818
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
1919
* Bump default `jackson` version to latest `2.19.2` -> `2.20.0`. ([#2606](https://github.com/diffplug/spotless/pull/2606))
2020
* Bump default `gson` version to latest `2.13.1` -> `2.13.2`. ([#2615](https://github.com/diffplug/spotless/pull/2615))
21+
* **BREAKING** Bump default `ktfmt` version to latest `0.53` -> `0.58` ([#2613](https://github.com/diffplug/spotless/pull/2613))
22+
* use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
2123

2224
## [3.3.1] - 2025-07-21
2325
### Fixed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ artifactIdMaven=spotless-maven-plugin
2121
artifactIdGradle=spotless-plugin-gradle
2222

2323
# Build requirements
24-
VER_JAVA=11
24+
VER_JAVA=17
2525
VER_JSR_305=3.0.2
2626

2727
# Dependencies provided by Spotless plugin

gradle/java-publish.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ javadoc {
7777
//
7878
// Thus, no javadoc warnings.
7979
options.addStringOption('Xdoclint:none', '-quiet')
80-
options.addStringOption('source', '11')
80+
options.addStringOption('source', '17')
8181
// setup the header
8282
options.header javadocInfo
8383
// setup links

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ dependencies {
104104
jacksonCompileOnly "com.fasterxml.jackson.core:jackson-databind:$VER_JACKSON"
105105
jacksonCompileOnly "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$VER_JACKSON"
106106
// ktfmt
107-
ktfmtCompileOnly "com.facebook:ktfmt:0.53"
107+
ktfmtCompileOnly "com.facebook:ktfmt:0.58"
108108
ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") {
109109
version {
110110
strictly '1.7' // for JDK 8 compatibility

lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 DiffPlug
2+
* Copyright 2022-2025 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.
@@ -28,8 +28,7 @@ public final class KtfmtFormatterFunc implements FormatterFunc {
2828
@Nonnull
2929
private final KtfmtStyle style;
3030

31-
@Nullable
32-
private final KtfmtFormattingOptions ktfmtFormattingOptions;
31+
@Nullable private final KtfmtFormattingOptions ktfmtFormattingOptions;
3332

3433
public KtfmtFormatterFunc() {
3534
this(KtfmtStyle.META, null);
@@ -55,29 +54,23 @@ public String apply(@Nonnull String input) throws Exception {
5554
}
5655

5756
private FormattingOptions createFormattingOptions() throws Exception {
58-
FormattingOptions formattingOptions;
59-
switch (style) {
60-
case META:
61-
formattingOptions = Formatter.META_FORMAT;
62-
break;
63-
case GOOGLE:
64-
formattingOptions = Formatter.GOOGLE_FORMAT;
65-
break;
66-
case KOTLIN_LANG:
67-
formattingOptions = Formatter.KOTLINLANG_FORMAT;
68-
break;
69-
default:
70-
throw new IllegalStateException("Unknown formatting option " + style);
71-
}
57+
FormattingOptions formattingOptions = switch (style) {
58+
case META -> Formatter.META_FORMAT;
59+
case GOOGLE -> Formatter.GOOGLE_FORMAT;
60+
case KOTLIN_LANG -> Formatter.KOTLINLANG_FORMAT;
61+
default -> throw new IllegalStateException("Unknown formatting option " + style);
62+
};
7263

7364
if (ktfmtFormattingOptions != null) {
7465
formattingOptions = formattingOptions.copy(
75-
ktfmtFormattingOptions.getMaxWidth().orElse(formattingOptions.getMaxWidth()),
76-
ktfmtFormattingOptions.getBlockIndent().orElse(formattingOptions.getBlockIndent()),
77-
ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getContinuationIndent()),
78-
ktfmtFormattingOptions.getManageTrailingCommas().orElse(formattingOptions.getManageTrailingCommas()),
79-
ktfmtFormattingOptions.getRemoveUnusedImports().orElse(formattingOptions.getRemoveUnusedImports()),
80-
formattingOptions.getDebuggingPrintOpsAfterFormatting());
66+
ktfmtFormattingOptions.getMaxWidth().orElse(formattingOptions.getMaxWidth()),
67+
ktfmtFormattingOptions.getBlockIndent().orElse(formattingOptions.getBlockIndent()),
68+
ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getContinuationIndent()),
69+
ktfmtFormattingOptions.getTrailingCommaManagementStrategy()
70+
.map(KtfmtTrailingCommaManagementStrategy::toFormatterTrailingCommaManagementStrategy)
71+
.orElse(formattingOptions.getTrailingCommaManagementStrategy()),
72+
ktfmtFormattingOptions.getRemoveUnusedImports().orElse(formattingOptions.getRemoveUnusedImports()),
73+
formattingOptions.getDebuggingPrintOpsAfterFormatting());
8174
}
8275

8376
return formattingOptions;

lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormattingOptions.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 DiffPlug
2+
* Copyright 2022-2025 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.
@@ -22,32 +22,27 @@
2222

2323
public final class KtfmtFormattingOptions {
2424

25-
@Nullable
26-
private Integer maxWidth;
25+
@Nullable private Integer maxWidth;
2726

28-
@Nullable
29-
private Integer blockIndent;
27+
@Nullable private Integer blockIndent;
3028

31-
@Nullable
32-
private Integer continuationIndent;
29+
@Nullable private Integer continuationIndent;
3330

34-
@Nullable
35-
private Boolean removeUnusedImports;
31+
@Nullable private Boolean removeUnusedImports;
3632

37-
@Nullable
38-
private Boolean manageTrailingCommas;
33+
@Nullable private KtfmtTrailingCommaManagementStrategy trailingCommaManagementStrategy;
3934

4035
public KtfmtFormattingOptions(
4136
@Nullable Integer maxWidth,
4237
@Nullable Integer blockIndent,
4338
@Nullable Integer continuationIndent,
4439
@Nullable Boolean removeUnusedImports,
45-
@Nullable Boolean manageTrailingCommas) {
40+
@Nullable KtfmtTrailingCommaManagementStrategy trailingCommaManagementStrategy) {
4641
this.maxWidth = maxWidth;
4742
this.blockIndent = blockIndent;
4843
this.continuationIndent = continuationIndent;
4944
this.removeUnusedImports = removeUnusedImports;
50-
this.manageTrailingCommas = manageTrailingCommas;
45+
this.trailingCommaManagementStrategy = trailingCommaManagementStrategy;
5146
}
5247

5348
@Nonnull
@@ -71,8 +66,8 @@ public Optional<Boolean> getRemoveUnusedImports() {
7166
}
7267

7368
@Nonnull
74-
public Optional<Boolean> getManageTrailingCommas() {
75-
return Optional.ofNullable(manageTrailingCommas);
69+
public Optional<KtfmtTrailingCommaManagementStrategy> getTrailingCommaManagementStrategy() {
70+
return Optional.ofNullable(trailingCommaManagementStrategy);
7671
}
7772

7873
public void setMaxWidth(int maxWidth) {
@@ -100,7 +95,7 @@ public void setRemoveUnusedImports(boolean removeUnusedImports) {
10095
this.removeUnusedImports = removeUnusedImports;
10196
}
10297

103-
public void setManageTrailingCommas(boolean manageTrailingCommas) {
104-
this.manageTrailingCommas = manageTrailingCommas;
98+
public void setTrailingCommaManagementStrategy(@Nullable KtfmtTrailingCommaManagementStrategy trailingCommaManagementStrategy) {
99+
this.trailingCommaManagementStrategy = trailingCommaManagementStrategy;
105100
}
106101
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.glue.ktfmt;
17+
18+
import com.facebook.ktfmt.format.TrailingCommaManagementStrategy;
19+
20+
public enum KtfmtTrailingCommaManagementStrategy {
21+
NONE, ONLY_ADD, COMPLETE;
22+
23+
public TrailingCommaManagementStrategy toFormatterTrailingCommaManagementStrategy() {
24+
return switch (this) {
25+
case NONE -> TrailingCommaManagementStrategy.NONE;
26+
case ONLY_ADD -> TrailingCommaManagementStrategy.ONLY_ADD;
27+
case COMPLETE -> TrailingCommaManagementStrategy.COMPLETE;
28+
};
29+
}
30+
}

0 commit comments

Comments
 (0)