Skip to content

Commit 7140dcd

Browse files
committed
Merge branch 'main' into fix-RemoveWildcardImportsStep
2 parents 31302c8 + dca9a7a commit 7140dcd

File tree

7 files changed

+55
-42
lines changed

7 files changed

+55
-42
lines changed

CHANGES.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1515
* Bump JGit from `6.10.1` to `7.3.0` ([#2257](https://github.com/diffplug/spotless/pull/2257))
1616
* Adds support for worktrees (fixes [#1765](https://github.com/diffplug/spotless/issues/1765))
1717
* Bump default `google-java-format` version to latest `1.24.0` -> `1.28.0`. ([#2345](https://github.com/diffplug/spotless/pull/2345))
18+
* Bump default `gson` version to latest `2.13.1` -> `2.13.2`. ([#2615](https://github.com/diffplug/spotless/pull/2615))
19+
* Bump default `jackson` version to latest `2.19.2` -> `2.20.0`. ([#2606](https://github.com/diffplug/spotless/pull/2606))
20+
* Bump default `ktfmt` version to latest `0.53` -> `0.58` ([#2613](https://github.com/diffplug/spotless/pull/2613))
21+
* **BREAKING** use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
1822
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
23+
* Bump default `palantir-java-format` version to latest `2.57.0` -> `2.71.0`.
24+
### Fixed
25+
* Fix `spaceBeforeSeparator` in Jackson formatter. ([#2103](https://github.com/diffplug/spotless/pull/2103))
1926
* `GitPrePushHookInstaller` uses a lock to run gracefully if it is called many times in parallel. ([#2570](https://github.com/diffplug/spotless/pull/2570))
20-
* Bump default `jackson` version to latest `2.19.2` -> `2.20.0`. ([#2606](https://github.com/diffplug/spotless/pull/2606))
21-
* Bump default `gson` version to latest `2.13.1` -> `2.13.2`. ([#2615](https://github.com/diffplug/spotless/pull/2615))
22-
* **BREAKING** Bump default `ktfmt` version to latest `0.53` -> `0.58` ([#2613](https://github.com/diffplug/spotless/pull/2613))
23-
* use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
2427
### Added
2528
* Add a `lint` mode to `ReplaceRegexStep` ([#2571](https://github.com/diffplug/spotless/pull/2571))
2629

lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 DiffPlug
2+
* Copyright 2021-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.
@@ -23,7 +23,6 @@
2323
import com.fasterxml.jackson.core.JsonGenerator;
2424
import com.fasterxml.jackson.core.util.DefaultIndenter;
2525
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
26-
import com.fasterxml.jackson.core.util.Separators;
2726

2827
import com.diffplug.spotless.FormatterFunc;
2928
import com.diffplug.spotless.json.JacksonJsonConfig;
@@ -88,23 +87,23 @@ protected static class SpotlessJsonPrettyPrinter extends DefaultPrettyPrinter {
8887

8988
public SpotlessJsonPrettyPrinter(boolean spaceBeforeSeparator) {
9089
this.spaceBeforeSeparator = spaceBeforeSeparator;
90+
91+
if (_objectFieldValueSeparatorWithSpaces == null || _objectFieldValueSeparatorWithSpaces.isEmpty()) {
92+
return;
93+
}
94+
95+
// Keep the behavior consistent even if Jackson changes default behavior
96+
boolean startsWithSpace = Character.isWhitespace(_objectFieldValueSeparatorWithSpaces.charAt(0));
97+
if (spaceBeforeSeparator && !startsWithSpace) {
98+
_objectFieldValueSeparatorWithSpaces = String.format(" %s", _objectFieldValueSeparatorWithSpaces);
99+
} else if (!spaceBeforeSeparator && startsWithSpace) {
100+
_objectFieldValueSeparatorWithSpaces = _objectFieldValueSeparatorWithSpaces.substring(1);
101+
}
91102
}
92103

93104
@Override
94105
public DefaultPrettyPrinter createInstance() {
95106
return new SpotlessJsonPrettyPrinter(spaceBeforeSeparator);
96107
}
97-
98-
@Override
99-
public DefaultPrettyPrinter withSeparators(Separators separators) {
100-
this._separators = separators;
101-
if (spaceBeforeSeparator) {
102-
// This is Jackson default behavior
103-
this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " ";
104-
} else {
105-
this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " ";
106-
}
107-
return this;
108-
}
109108
}
110109
}

lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class PalantirJavaFormatStep implements Serializable {
2929
private static final String DEFAULT_STYLE = "PALANTIR";
3030
private static final String NAME = "palantir-java-format";
3131
public static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:";
32-
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "1.1.0").add(11, "2.28.0").add(21, "2.57.0");
32+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "1.1.0").add(11, "2.28.0").add(21, "2.71.0");
3333

3434
/** The jar that contains the formatter. */
3535
private final JarState.Promised jarState;

plugin-gradle/CHANGES.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
66
### Changed
77
* **BREAKING** Bump the required Gradle to `7.3` and required Java to `17`. ([#2375](https://github.com/diffplug/spotless/issues/2375), [#2540](https://github.com/diffplug/spotless/pull/2540))
88
* **BREAKING** `spotlessInstallGitPrePushHook` task is now installed only on the root project. ([#2570](https://github.com/diffplug/spotless/pull/2570))
9+
* Running `spotlessCheck` with violations unilaterally produces the error message `Run './gradlew spotlessApply' to fix these violations`. ([#2592](https://github.com/diffplug/spotless/issues/2592))
910
* Bump JGit from `6.10.1` to `7.3.0` ([#2257](https://github.com/diffplug/spotless/pull/2257))
1011
* Adds support for worktrees (fixes [#1765](https://github.com/diffplug/spotless/issues/1765))
1112
* Bump default `google-java-format` version to latest `1.24.0` -> `1.28.0`. ([#2345](https://github.com/diffplug/spotless/pull/2345))
12-
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
13+
* Bump default `gson` version to latest `2.13.1` -> `2.13.2`. ([#2615](https://github.com/diffplug/spotless/pull/2615))
1314
* Bump default `jackson` version to latest `2.19.2` -> `2.20.0`. ([#2606](https://github.com/diffplug/spotless/pull/2606))
14-
* Running `spotlessCheck` with violations unilaterally produces the error message `Run './gradlew spotlessApply' to fix these violations`. ([#2592](https://github.com/diffplug/spotless/issues/2592))
15-
* **BREAKING** Bump default `ktfmt` version to latest `0.53` -> `0.58` ([#2613](https://github.com/diffplug/spotless/pull/2613))
16-
* use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
15+
* Bump default `ktfmt` version to latest `0.53` -> `0.58` ([#2613](https://github.com/diffplug/spotless/pull/2613))
16+
* **BREAKING** use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
17+
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
18+
* Bump default `palantir-java-format` version to latest `2.57.0` -> `2.71.0`.
1719

1820
### Fixed
1921
* Respect system gitconfig when performing git operations ([#2404](https://github.com/diffplug/spotless/issues/2404))
22+
* Fix `spaceBeforeSeparator` in Jackson formatter. ([#2103](https://github.com/diffplug/spotless/pull/2103))
2023
* `spotlessInstallGitPrePushHook` is now compatible with configuration cache. ([#2570](https://github.com/diffplug/spotless/pull/2570))
2124

2225
## [7.2.1] - 2025-07-21

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ public JacksonJsonGradleConfig jsonFeature(String feature, boolean toggle) {
168168
return this;
169169
}
170170

171+
public JacksonJsonGradleConfig setSpaceBeforeSeparator(boolean value) {
172+
jacksonConfig.setSpaceBeforeSeparator(value);
173+
return this;
174+
}
175+
171176
@Override
172177
public JacksonJsonGradleConfig self() {
173178
return this;

plugin-maven/CHANGES.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
99
* Bump JGit from `6.10.1` to `7.3.0` ([#2257](https://github.com/diffplug/spotless/pull/2257))
1010
* Adds support for worktrees (fixes [#1765](https://github.com/diffplug/spotless/issues/1765))
1111
* Bump default `google-java-format` version to latest `1.24.0` -> `1.28.0`. ([#2345](https://github.com/diffplug/spotless/pull/2345))
12-
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
13-
* Bump default `jackson` version to latest `2.19.2` -> `2.20.0`. ([#2606](https://github.com/diffplug/spotless/pull/2606))
1412
* Bump default `gson` version to latest `2.13.1` -> `2.13.2`. ([#2615](https://github.com/diffplug/spotless/pull/2615))
15-
* **BREAKING** Bump default `ktfmt` version to latest `0.53` -> `0.58` ([#2613](https://github.com/diffplug/spotless/pull/2613))
16-
* use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
13+
* Bump default `jackson` version to latest `2.19.2` -> `2.20.0`. ([#2606](https://github.com/diffplug/spotless/pull/2606))
14+
* Bump default `ktfmt` version to latest `0.53` -> `0.58` ([#2613](https://github.com/diffplug/spotless/pull/2613))
15+
* **BREAKING** use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
16+
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
17+
* Bump default `palantir-java-format` version to latest `2.57.0` -> `2.71.0`.
18+
### Fixed
19+
* Fix `spaceBeforeSeparator` in Jackson formatter. ([#2103](https://github.com/diffplug/spotless/pull/2103))
1720

1821
## [2.46.1] - 2025-07-21
1922
### Fixed
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"A" : 1,
3-
"X" : 2,
4-
"_arraysNotSorted" : [ 3, 2, 1 ],
5-
"_objectsInArraysAreSorted" : [ {
6-
"a" : 1,
7-
"b" : 2
2+
"A": 1,
3+
"X": 2,
4+
"_arraysNotSorted": [ 3, 2, 1 ],
5+
"_objectsInArraysAreSorted": [ {
6+
"a": 1,
7+
"b": 2
88
} ],
9-
"a" : 3,
10-
"c" : 4,
11-
"x" : 5,
12-
"z" : {
13-
"A" : 1,
14-
"X" : 2,
15-
"a" : 3,
16-
"c" : 4,
17-
"x" : 5
9+
"a": 3,
10+
"c": 4,
11+
"x": 5,
12+
"z": {
13+
"A": 1,
14+
"X": 2,
15+
"a": 3,
16+
"c": 4,
17+
"x": 5
1818
}
1919
}

0 commit comments

Comments
 (0)