Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
* Bump default `jackson` version to latest `2.19.2` -> `2.20.0`. ([#2606](https://github.com/diffplug/spotless/pull/2606))
* Bump default `gson` version to latest `2.13.1` -> `2.13.2`. ([#2615](https://github.com/diffplug/spotless/pull/2615))
* **BREAKING** Bump default `ktfmt` version to latest `0.53` -> `0.58` ([#2613](https://github.com/diffplug/spotless/pull/2613))
* use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option

## [3.3.1] - 2025-07-21
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ artifactIdMaven=spotless-maven-plugin
artifactIdGradle=spotless-plugin-gradle

# Build requirements
VER_JAVA=11
VER_JAVA=17
VER_JSR_305=3.0.2

# Dependencies provided by Spotless plugin
Expand Down
2 changes: 1 addition & 1 deletion gradle/java-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ javadoc {
//
// Thus, no javadoc warnings.
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('source', '11')
options.addStringOption('source', '17')
// setup the header
options.header javadocInfo
// setup links
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ dependencies {
jacksonCompileOnly "com.fasterxml.jackson.core:jackson-databind:$VER_JACKSON"
jacksonCompileOnly "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$VER_JACKSON"
// ktfmt
ktfmtCompileOnly "com.facebook:ktfmt:0.53"
ktfmtCompileOnly "com.facebook:ktfmt:0.58"
ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") {
version {
strictly '1.7' // for JDK 8 compatibility
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 DiffPlug
* Copyright 2022-2025 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 @@ -28,8 +28,7 @@ public final class KtfmtFormatterFunc implements FormatterFunc {
@Nonnull
private final KtfmtStyle style;

@Nullable
private final KtfmtFormattingOptions ktfmtFormattingOptions;
@Nullable private final KtfmtFormattingOptions ktfmtFormattingOptions;

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

private FormattingOptions createFormattingOptions() throws Exception {
FormattingOptions formattingOptions;
switch (style) {
case META:
formattingOptions = Formatter.META_FORMAT;
break;
case GOOGLE:
formattingOptions = Formatter.GOOGLE_FORMAT;
break;
case KOTLIN_LANG:
formattingOptions = Formatter.KOTLINLANG_FORMAT;
break;
default:
throw new IllegalStateException("Unknown formatting option " + style);
}
FormattingOptions formattingOptions = switch (style) {
case META -> Formatter.META_FORMAT;
case GOOGLE -> Formatter.GOOGLE_FORMAT;
case KOTLIN_LANG -> Formatter.KOTLINLANG_FORMAT;
default -> throw new IllegalStateException("Unknown formatting option " + style);
};

if (ktfmtFormattingOptions != null) {
formattingOptions = formattingOptions.copy(
ktfmtFormattingOptions.getMaxWidth().orElse(formattingOptions.getMaxWidth()),
ktfmtFormattingOptions.getBlockIndent().orElse(formattingOptions.getBlockIndent()),
ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getContinuationIndent()),
ktfmtFormattingOptions.getManageTrailingCommas().orElse(formattingOptions.getManageTrailingCommas()),
ktfmtFormattingOptions.getRemoveUnusedImports().orElse(formattingOptions.getRemoveUnusedImports()),
formattingOptions.getDebuggingPrintOpsAfterFormatting());
ktfmtFormattingOptions.getMaxWidth().orElse(formattingOptions.getMaxWidth()),
ktfmtFormattingOptions.getBlockIndent().orElse(formattingOptions.getBlockIndent()),
ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getContinuationIndent()),
ktfmtFormattingOptions.getTrailingCommaManagementStrategy()
.map(KtfmtTrailingCommaManagementStrategy::toFormatterTrailingCommaManagementStrategy)
.orElse(formattingOptions.getTrailingCommaManagementStrategy()),
ktfmtFormattingOptions.getRemoveUnusedImports().orElse(formattingOptions.getRemoveUnusedImports()),
formattingOptions.getDebuggingPrintOpsAfterFormatting());
}

return formattingOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 DiffPlug
* Copyright 2022-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,32 +22,27 @@

public final class KtfmtFormattingOptions {

@Nullable
private Integer maxWidth;
@Nullable private Integer maxWidth;

@Nullable
private Integer blockIndent;
@Nullable private Integer blockIndent;

@Nullable
private Integer continuationIndent;
@Nullable private Integer continuationIndent;

@Nullable
private Boolean removeUnusedImports;
@Nullable private Boolean removeUnusedImports;

@Nullable
private Boolean manageTrailingCommas;
@Nullable private KtfmtTrailingCommaManagementStrategy trailingCommaManagementStrategy;

public KtfmtFormattingOptions(
@Nullable Integer maxWidth,
@Nullable Integer blockIndent,
@Nullable Integer continuationIndent,
@Nullable Boolean removeUnusedImports,
@Nullable Boolean manageTrailingCommas) {
@Nullable KtfmtTrailingCommaManagementStrategy trailingCommaManagementStrategy) {
this.maxWidth = maxWidth;
this.blockIndent = blockIndent;
this.continuationIndent = continuationIndent;
this.removeUnusedImports = removeUnusedImports;
this.manageTrailingCommas = manageTrailingCommas;
this.trailingCommaManagementStrategy = trailingCommaManagementStrategy;
}

@Nonnull
Expand All @@ -71,8 +66,8 @@ public Optional<Boolean> getRemoveUnusedImports() {
}

@Nonnull
public Optional<Boolean> getManageTrailingCommas() {
return Optional.ofNullable(manageTrailingCommas);
public Optional<KtfmtTrailingCommaManagementStrategy> getTrailingCommaManagementStrategy() {
return Optional.ofNullable(trailingCommaManagementStrategy);
}

public void setMaxWidth(int maxWidth) {
Expand Down Expand Up @@ -100,7 +95,7 @@ public void setRemoveUnusedImports(boolean removeUnusedImports) {
this.removeUnusedImports = removeUnusedImports;
}

public void setManageTrailingCommas(boolean manageTrailingCommas) {
this.manageTrailingCommas = manageTrailingCommas;
public void setTrailingCommaManagementStrategy(@Nullable KtfmtTrailingCommaManagementStrategy trailingCommaManagementStrategy) {
this.trailingCommaManagementStrategy = trailingCommaManagementStrategy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.glue.ktfmt;

import com.facebook.ktfmt.format.TrailingCommaManagementStrategy;

public enum KtfmtTrailingCommaManagementStrategy {
NONE, ONLY_ADD, COMPLETE;

public TrailingCommaManagementStrategy toFormatterTrailingCommaManagementStrategy() {
return switch (this) {
case NONE -> TrailingCommaManagementStrategy.NONE;
case ONLY_ADD -> TrailingCommaManagementStrategy.ONLY_ADD;
case COMPLETE -> TrailingCommaManagementStrategy.COMPLETE;
};
}
}
Loading
Loading