Skip to content

Commit c59cadd

Browse files
committed
Merge branch 'main' into subgroup-catch-all
2 parents 6688e3f + 66b8dd2 commit c59cadd

File tree

108 files changed

+3439
-289
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+3439
-289
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# NEXUS_USER
33
# NEXUS_PASS
44
# GPG_PASSPHRASE
5-
# GPG_KEY (base64)
5+
# GPG_KEY64 (base64)
66
# gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy
77
# GRADLE_PORTAL_KEY
88
# GRADLE_PORTAL_SECRET
@@ -29,11 +29,9 @@ jobs:
2929
env:
3030
gh_token: ${{ secrets.GH_TOKEN }}
3131
ORG_GRADLE_PROJECT_nexus_user: ${{ secrets.NEXUS_USER }}
32-
ORG_GRADLE_PROJECT_nexus_pass: ${{ secrets.NEXUS_PASS }}
32+
ORG_GRADLE_PROJECT_nexus_pass64: ${{ secrets.NEXUS_PASS64 }}
3333
ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
34-
ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY }}
35-
36-
gradle_key
34+
ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }}
3735
steps:
3836
- uses: actions/checkout@v3
3937
- name: jdk 11

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,6 @@ nbdist/
121121
nbactions.xml
122122
nb-configuration.xml
123123
.nb-gradle/
124+
125+
# MacOS jenv
126+
.java-version

CHANGES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1414
* Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142)
1515
* **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`.
1616
* Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)).
17+
* Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478))
18+
* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453))
19+
* Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995))
1720
### Fixed
1821
* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444))
1922
* Fix subgroups leading catch all matcher.
20-
2123
### Changes
24+
* Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453))
2225
* Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409))
2326
* We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml`
2427
* Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443))
@@ -30,6 +33,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
3033
* Switch our publishing infrastructure from CircleCI to GitHub Actions ([#1462](https://github.com/diffplug/spotless/pull/1462)).
3134
* Help wanted for moving our tests too ([#1472](https://github.com/diffplug/spotless/issues/1472))
3235

36+
3337
## [2.31.1] - 2023-01-02
3438
### Fixed
3539
* Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426))

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}}
6969
lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7070
lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
7171
lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
72+
lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7273
lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7374
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7475
lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
7576
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
7677
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
7778
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
7879
extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
80+
lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
7981
'| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} | {{no}} |',
8082
].join('\n');
8183
-->
@@ -113,13 +115,15 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}}
113115
| [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
114116
| [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
115117
| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
118+
| [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
116119
| [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
117120
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
118121
| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
119122
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
120123
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
121124
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
122125
| [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
126+
| [`yaml.YamlJacksonStep`](lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
123127
| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | :white_large_square: |
124128
<!---freshmark /matrix -->
125129

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ VER_SLF4J=[1.6,2.0[
2626
# Used in multiple places
2727
VER_DURIAN=1.2.0
2828
VER_JGIT=5.13.1.202206130422-r
29-
VER_JUNIT=5.9.1
29+
VER_JUNIT=5.9.2
3030
VER_ASSERTJ=3.24.1
3131
VER_MOCKITO=4.11.0
3232

gradle/java-publish.gradle

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
import java.nio.charset.StandardCharsets
2+
3+
def decode64(String varName) {
4+
String envValue = System.env[varName]
5+
if (envValue == null) {
6+
return ""
7+
} else {
8+
return new String(envValue.decodeBase64(), "UTF-8")
9+
}
10+
}
111

212
if (project.parent == null) {
313
group = 'com.diffplug.spotless'
14+
def pass = System.env['ORG_GRADLE_PROJECT_nexus_pass64']
15+
if (pass != null) {
16+
pass = pass.decodeBase64()
17+
}
418
// it's the root project
519
apply plugin: 'io.github.gradle-nexus.publish-plugin'
620
nexusPublishing {
@@ -9,7 +23,7 @@ if (project.parent == null) {
923
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
1024
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
1125
username = System.env['ORG_GRADLE_PROJECT_nexus_user']
12-
password = System.env['ORG_GRADLE_PROJECT_nexus_pass']
26+
password = decode64('ORG_GRADLE_PROJECT_nexus_pass64')
1327
}
1428
}
1529
}
@@ -158,7 +172,7 @@ model {
158172

159173
if (!version.endsWith('-SNAPSHOT')) {
160174
signing {
161-
String gpg_key = new String(System.env['ORG_GRADLE_PROJECT_gpg_key64'].decodeBase64())
175+
String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64')
162176
useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase'])
163177
sign(publishing.publications)
164178
}

lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 DiffPlug
2+
* Copyright 2020-2023 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.

lib/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def NEEDS_GLUE = [
1414
'ktlint',
1515
'flexmark',
1616
'diktat',
17-
'scalafmt'
17+
'scalafmt',
18+
'jackson'
1819
]
1920
for (glue in NEEDS_GLUE) {
2021
sourceSets.register(glue) {
@@ -55,6 +56,9 @@ dependencies {
5556

5657
palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm
5758

59+
// used jackson-based formatters
60+
jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1'
61+
5862
String VER_KTFMT = '0.42'
5963
ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT"
6064
String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright 2021-2023 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.yaml;
17+
18+
import java.io.IOException;
19+
import java.util.List;
20+
21+
import com.fasterxml.jackson.core.JsonProcessingException;
22+
import com.fasterxml.jackson.core.type.TypeReference;
23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
import com.fasterxml.jackson.databind.SerializationFeature;
25+
import com.fasterxml.jackson.databind.node.ObjectNode;
26+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
27+
28+
import com.diffplug.spotless.FormatterFunc;
29+
30+
public class YamlJacksonFormatterFunc implements FormatterFunc {
31+
private List<String> enabledFeatures;
32+
private List<String> disabledFeatures;
33+
34+
public YamlJacksonFormatterFunc(List<String> enabledFeatures, List<String> disabledFeatures) {
35+
this.enabledFeatures = enabledFeatures;
36+
this.disabledFeatures = disabledFeatures;
37+
}
38+
39+
@Override
40+
public String apply(String input) throws Exception {
41+
ObjectMapper objectMapper = makeObjectMapper();
42+
43+
return format(objectMapper, input);
44+
}
45+
46+
protected ObjectMapper makeObjectMapper() {
47+
YAMLFactory yamlFactory = new YAMLFactory();
48+
ObjectMapper objectMapper = new ObjectMapper(yamlFactory);
49+
50+
// Configure the ObjectMapper
51+
// https://github.com/FasterXML/jackson-databind#commonly-used-features
52+
for (String rawFeature : enabledFeatures) {
53+
// https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection
54+
SerializationFeature feature = SerializationFeature.valueOf(rawFeature);
55+
56+
objectMapper.enable(feature);
57+
}
58+
59+
for (String rawFeature : disabledFeatures) {
60+
// https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection
61+
SerializationFeature feature = SerializationFeature.valueOf(rawFeature);
62+
63+
objectMapper.disable(feature);
64+
}
65+
return objectMapper;
66+
}
67+
68+
protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException {
69+
// We may consider adding manually an initial '---' prefix to help management of multiple documents
70+
// if (!input.trim().startsWith("---")) {
71+
// input = "---" + "\n" + input;
72+
// }
73+
74+
try {
75+
// https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson
76+
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648
77+
// 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value'
78+
// JsonParser yamlParser = objectMapper.getFactory().createParser(input);
79+
// List<ObjectNode> docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll();
80+
// return objectMapper.writeValueAsString(docs);
81+
82+
// 2023-01: This returns JSON instead of YAML
83+
// This will transit with a JsonNode
84+
// A JsonNode may keep the comments from the input node
85+
// JsonNode jsonNode = objectMapper.readTree(input);
86+
//Not 'toPrettyString' as one could require no INDENT_OUTPUT
87+
// return jsonNode.toPrettyString();
88+
ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class);
89+
return objectMapper.writeValueAsString(objectNode);
90+
} catch (JsonProcessingException e) {
91+
throw new AssertionError("Unable to format YAML. input='" + input + "'", e);
92+
}
93+
}
94+
95+
// Spotbugs
96+
private static class ObjectNodeTypeReference extends TypeReference<ObjectNode> {}
97+
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2023 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.
@@ -198,8 +198,9 @@ private String buildUpgradeFormatterMessage(V fmtVersion) {
198198
StringBuilder builder = new StringBuilder();
199199
V recommendedFmtVersionOrNull = getRecommendedFormatterVersion();
200200
if (null != recommendedFmtVersionOrNull && (fmtVersionComparator.compare(fmtVersion, recommendedFmtVersionOrNull) < 0)) {
201-
builder.append(String.format("You are not using latest version on JVM %d+.%n", getRequiredJvmVersion(recommendedFmtVersionOrNull)));
202-
builder.append(String.format("Try to upgrade to %s %s, which may have fixed this problem.", fmtName, getRecommendedFormatterVersion()));
201+
builder.append(String.format("%s %s is currently being used, but outdated.%n", fmtName, fmtVersion));
202+
builder.append(String.format("%s %s is the recommended version, which may have fixed this problem.%n", fmtName, recommendedFmtVersionOrNull));
203+
builder.append(String.format("%s %s requires JVM %d+.", fmtName, recommendedFmtVersionOrNull, getRequiredJvmVersion(recommendedFmtVersionOrNull)));
203204
} else {
204205
V higherFormatterVersionOrNull = fmt2jvmVersion.higherKey(fmtVersion);
205206
if (null != higherFormatterVersionOrNull) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2016-2023 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.npm;
17+
18+
abstract class BaseNpmRestService {
19+
20+
protected final SimpleRestClient restClient;
21+
22+
BaseNpmRestService(String baseUrl) {
23+
this.restClient = SimpleRestClient.forBaseUrl(baseUrl);
24+
}
25+
26+
public String shutdown() {
27+
return restClient.post("/shutdown");
28+
}
29+
30+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2016-2023 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.npm;
17+
18+
import java.io.File;
19+
import java.io.IOException;
20+
import java.io.Serializable;
21+
22+
import javax.annotation.Nullable;
23+
24+
import com.diffplug.spotless.FileSignature;
25+
import com.diffplug.spotless.ThrowingEx;
26+
27+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
28+
29+
public class EslintConfig implements Serializable {
30+
31+
private static final long serialVersionUID = -6196834313082791248L;
32+
33+
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
34+
@Nullable
35+
private final transient File eslintConfigPath;
36+
37+
@SuppressWarnings("unused")
38+
private final FileSignature eslintConfigPathSignature;
39+
40+
private final String eslintConfigJs;
41+
42+
public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) {
43+
try {
44+
this.eslintConfigPath = eslintConfigPath;
45+
this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList();
46+
this.eslintConfigJs = eslintConfigJs;
47+
} catch (IOException e) {
48+
throw ThrowingEx.asRuntime(e);
49+
}
50+
}
51+
52+
public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) {
53+
return new EslintConfig(eslintConfigPath, this.eslintConfigJs);
54+
}
55+
56+
@Nullable
57+
public File getEslintConfigPath() {
58+
return eslintConfigPath;
59+
}
60+
61+
@Nullable
62+
public String getEslintConfigJs() {
63+
return eslintConfigJs;
64+
}
65+
66+
public EslintConfig verify() {
67+
if (eslintConfigPath == null && eslintConfigJs == null) {
68+
throw new IllegalArgumentException("ESLint must be configured using either a configFile or a configJs - but both are null.");
69+
}
70+
return this;
71+
}
72+
}

0 commit comments

Comments
 (0)