Skip to content

Commit 8ebb896

Browse files
committed
Merge remote-tracking branch 'upstream/main' into 1480-speedup-npm-install-step-for-npm-based-formatters
# Conflicts: # CHANGES.md # plugin-gradle/CHANGES.md # plugin-maven/CHANGES.md
2 parents 78ccbc9 + 6716228 commit 8ebb896

File tree

12 files changed

+99
-12
lines changed

12 files changed

+99
-12
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1111

1212
## [Unreleased]
1313
### Added
14+
* `gradlew equoIde` opens a repeatable clean Spotless dev environment. ([#1523](https://github.com/diffplug/spotless/pull/1523))
15+
* `cleanthat` added `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574))
1416
* `npm`-based formatters now support caching of `node_modules` directory ([#1590](https://github.com/diffplug/spotless/pull/1590))
1517
### Fixed
18+
* `JacksonJsonFormatterFunc` handles json files with an Array as root. ([#1585](https://github.com/diffplug/spotless/pull/1585))
19+
### Changes
20+
* Bump default `cleanthat` version to latest `2.1` -> `2.6` ([#1569](https://github.com/diffplug/spotless/pull/1569) and [#1574](https://github.com/diffplug/spotless/pull/1574))
1621
* Reduce logging-noise created by `npm`-based formatters ([#1590](https://github.com/diffplug/spotless/pull/1590) fixes [#1582](https://github.com/diffplug/spotless/issues/1582))
1722

1823
## [2.35.0] - 2023-02-10

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing to Spotless
22

3-
Pull requests are welcome, preferably against `main`. Feel free to develop spotless any way you like.
3+
Pull requests are welcome, preferably against `main`. Feel free to develop spotless any way you like, but if you like Eclipse and Gradle Buildship then [`gradlew equoIde` will install an IDE and set it up for you](https://github.com/equodev/equo-ide).
44

55
## How Spotless works
66

build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
plugins {
2+
// https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md
3+
id 'dev.equo.ide' version '0.16.0'
4+
}
5+
equoIde {
6+
branding().title('Spotless').icon(file('_images/spotless_logo.png'))
7+
welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md')
8+
gradleBuildship()
9+
}
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
115
apply from: rootProject.file('gradle/java-publish.gradle')
216
apply from: rootProject.file('gradle/changelog.gradle')
317
allprojects {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.diffplug.spotless.glue.json;
1717

1818
import java.io.IOException;
19-
import java.util.Map;
2019

2120
import com.fasterxml.jackson.core.JsonFactory;
2221
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -49,7 +48,7 @@ public String apply(String input) throws Exception {
4948
protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException {
5049
try {
5150
// ObjectNode is not compatible with SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS
52-
Map objectNode = objectMapper.readValue(input, Map.class);
51+
Object objectNode = objectMapper.readValue(input, inferType(input));
5352
String output = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode);
5453

5554
return output;
@@ -58,6 +57,13 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA
5857
}
5958
}
6059

60+
/**
61+
*
62+
* @param input
63+
* @return the {@link Class} into which the String has to be deserialized
64+
*/
65+
protected abstract Class<?> inferType(String input);
66+
6167
/**
6268
* @return a {@link JsonFactory}. May be overridden to handle alternative formats.
6369
* @see <a href="https://github.com/FasterXML/jackson-dataformats-text">jackson-dataformats-text</a>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package com.diffplug.spotless.glue.json;
1717

18+
import java.util.Collection;
19+
import java.util.Map;
20+
1821
import com.fasterxml.jackson.core.JsonFactory;
1922
import com.fasterxml.jackson.core.JsonFactoryBuilder;
2023
import com.fasterxml.jackson.core.JsonGenerator;
@@ -37,6 +40,15 @@ public JacksonJsonFormatterFunc(JacksonJsonConfig jacksonConfig) {
3740
this.jacksonConfig = jacksonConfig;
3841
}
3942

43+
@Override
44+
protected Class<?> inferType(String input) {
45+
if (input.trim().startsWith("[")) {
46+
return Collection.class;
47+
} else {
48+
return Map.class;
49+
}
50+
}
51+
4052
/**
4153
* @return a {@link JsonFactory}. May be overridden to handle alternative formats.
4254
* @see <a href="https://github.com/FasterXML/jackson-dataformats-text">jackson-dataformats-text</a>

lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ protected JsonFactory makeJsonFactory() {
5858
return yamlFactoryBuilder.build();
5959
}
6060

61+
@Override
62+
protected Class<?> inferType(String input) {
63+
return JsonNode.class;
64+
}
65+
6166
@Override
6267
protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException {
6368
try {
6469
// https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson
6570
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648
6671
JsonParser yamlParser = objectMapper.getFactory().createParser(input);
67-
List<JsonNode> documents = objectMapper.readValues(yamlParser, JsonNode.class).readAll();
72+
List<?> documents = objectMapper.readValues(yamlParser, inferType(input)).readAll();
6873

6974
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055
7075
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055

lib/src/main/java/com/diffplug/spotless/json/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@ParametersAreNonnullByDefault
22
@ReturnValuesAreNonnullByDefault
3-
package com.diffplug.spotless.extra.json.java;
3+
package com.diffplug.spotless.json;
44

55
import javax.annotation.ParametersAreNonnullByDefault;
66

plugin-gradle/CHANGES.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66
### Added
7-
* Add `includeDraft` option, to include draft mutators from composite mutators ([#1574](https://github.com/diffplug/spotless/pull/1574))
7+
* `cleanthat` now has `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574))
88
* `npm`-based formatters (`prettier`, `tsfmt` and `eslint`) now support caching of `node_modules` directory.
99
To enable it, provide `npmInstallCache()` option. ([#1590](https://github.com/diffplug/spotless/pull/1590))
10+
### Fixed
11+
* `json { jackson()` can now handle `Array` as a root element. ([#1585](https://github.com/diffplug/spotless/pull/1585))
12+
* Reduce logging-noise created by `npm`-based formatters ([#1590](https://github.com/diffplug/spotless/pull/1590) fixes [#1582](https://github.com/diffplug/spotless/issues/1582))
1013
### Changes
11-
* Bump default `cleanthat` version to latest `2.2` -> `2.6` ([#1574](https://github.com/diffplug/spotless/pull/1574))
12-
* Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569))
14+
* Bump default `cleanthat` version to latest `2.1` -> `2.6`. ([#1569](https://github.com/diffplug/spotless/pull/1569) and [#1574](https://github.com/diffplug/spotless/pull/1574))
1315

1416
## [6.15.0] - 2023-02-10
1517
### Added

plugin-maven/CHANGES.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66
### Added
7-
* Add `includeDraft` option, to include draft mutators from composite mutators ([#XXX](https://github.com/diffplug/spotless/pull/XXX))
7+
* `cleanthat` added `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574))
88
* `npm`-based formatters (`prettier`, `tsfmt` and `eslint`) now support caching of `node_modules` directory.
99
To enable it, provide the `<npmInstallCache>` option. ([#1590](https://github.com/diffplug/spotless/pull/1590))
10+
### Fixed
11+
* `<json><jackson>` can now handle `Array` as a root element. ([#1585](https://github.com/diffplug/spotless/pull/1585))
12+
* Reduce logging-noise created by `npm`-based formatters ([#1590](https://github.com/diffplug/spotless/pull/1590) fixes [#1582](https://github.com/diffplug/spotless/issues/1582))
1013
### Changes
11-
* Bump default `cleanthat` version to latest `2.2` -> `2.6` ([#1574](https://github.com/diffplug/spotless/pull/1574))
12-
* Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569))
14+
* Bump default `cleanthat` version to latest `2.1` -> `2.6` ([#1569](https://github.com/diffplug/spotless/pull/1569) and [#1574](https://github.com/diffplug/spotless/pull/1574))
1315

1416
## [2.33.0] - 2023-02-10
1517
### Added
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[ 1, 2, 3, 4 ]

0 commit comments

Comments
 (0)