Skip to content

Commit 84547c6

Browse files
committed
Merge branch 'renovate/ver_diktat' into renovate/ver_scalafmt
2 parents 939d45f + 9568a97 commit 84547c6

File tree

70 files changed

+1576
-149
lines changed

Some content is hidden

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

70 files changed

+1576
-149
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ indent_style = space
2525
[*.{yml,yaml}]
2626
indent_style = space
2727
indent_size = 2
28+
29+
# Prevent unexpected automatic indentation when crafting test-cases
30+
[/testlib/src/main/resources/**]
31+
charset = unset
32+
end_of_line = unset
33+
insert_final_newline = unset
34+
trim_trailing_whitespace = unset
35+
indent_style = unset
36+
indent_size = unset
37+
ij_formatter_enabled = false

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Added
1414
* Support configuration of mirrors for P2 repositories in `EquoBasedStepBuilder` ([#1629](https://github.com/diffplug/spotless/issues/1629)).
15+
* The `style` option in Palantir Java Format ([#1654](https://github.com/diffplug/spotless/pull/1654)).
16+
* Added formatter for Gherkin feature files ([#1649](https://github.com/diffplug/spotless/issues/1649)).
1517
### Changes
1618
* **POTENTIALLY BREAKING** Converted `googleJavaFormat` to a compile-only dependency and drop support for versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630))
19+
* Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589)
1720
* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630))
21+
* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302))
22+
* Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631))
1823

1924
## [2.37.0] - 2023-03-13
2025
### Added

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ lib('generic.TrimTrailingWhitespaceStep') +'{{yes}} | {{yes}}
7777
lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7878
lib('cpp.ClangFormatStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
7979
extra('cpp.EclipseFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
80+
lib('gherkin.GherkinUtilsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
8081
extra('groovy.GrEclipseFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
8182
lib('java.GoogleJavaFormatStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
8283
lib('java.ImportOrderStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
@@ -125,6 +126,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
125126
| [`antlr4.Antlr4FormatterStep`](lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
126127
| [`cpp.ClangFormatStep`](lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
127128
| [`cpp.EclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
129+
| [`gherkin.GherkinUtilsStep`](lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
128130
| [`groovy.GrEclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
129131
| [`java.GoogleJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
130132
| [`java.ImportOrderStep`](lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java) | :+1: | :+1: | :+1: | :white_large_square: |

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
For security disclosures, please send an email to [email protected]

lib/build.gradle

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def NEEDS_GLUE = [
1818
'scalafmt',
1919
'jackson',
2020
'gson',
21-
'cleanthat'
21+
'cleanthat',
22+
'gherkin'
2223
]
2324
for (glue in NEEDS_GLUE) {
2425
sourceSets.register(glue) {
@@ -71,7 +72,7 @@ dependencies {
7172

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

74-
googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.8' // minimum required version due to api changes before then
75+
googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.16.0' // minimum required version due to api changes before then
7576

7677
// used jackson-based formatters
7778
jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
@@ -105,16 +106,20 @@ dependencies {
105106
String VER_SCALAFMT="3.7.3"
106107
scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT"
107108

108-
String VER_DIKTAT = "1.2.4.2"
109+
String VER_DIKTAT = "1.2.5"
109110
diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT"
110111

111112
// used for markdown formatting
112-
flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2'
113+
flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.64.0'
113114

114115
gsonCompileOnly 'com.google.code.gson:gson:2.10.1'
115116

116-
cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.6'
117-
compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.6'
117+
String VER_CLEANTHAT="2.8"
118+
cleanthatCompileOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT"
119+
compatCleanthat2Dot1CompileAndTestOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT"
120+
121+
gherkinCompileOnly 'io.cucumber:gherkin-utils:8.0.2'
122+
gherkinCompileOnly 'org.slf4j:slf4j-api:2.0.0'
118123
}
119124

120125
// we'll hold the core lib to a high standard

lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ private String doApply(String input) throws InterruptedException, IOException {
8888
LOGGER.debug("Processing sourceJdk={} included={} excluded={}", jdkVersion, included, excluded, includeDraft);
8989
LOGGER.debug("Available mutators: {}", JavaRefactorer.getAllIncluded());
9090

91-
// Spotless calls steps always with LF eol.
92-
return refactorer.doFormat(input, LineEnding.LF);
91+
return refactorer.doFormat(input);
9392
}
9493

9594
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 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.gherkin;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
21+
import com.diffplug.spotless.FormatterFunc;
22+
import com.diffplug.spotless.gherkin.GherkinUtilsConfig;
23+
24+
import io.cucumber.gherkin.GherkinParser;
25+
import io.cucumber.gherkin.utils.pretty.Pretty;
26+
import io.cucumber.gherkin.utils.pretty.Syntax;
27+
import io.cucumber.messages.types.Envelope;
28+
import io.cucumber.messages.types.GherkinDocument;
29+
import io.cucumber.messages.types.Source;
30+
import io.cucumber.messages.types.SourceMediaType;
31+
32+
public class GherkinUtilsFormatterFunc implements FormatterFunc {
33+
private static final Logger LOGGER = LoggerFactory.getLogger(GherkinUtilsFormatterFunc.class);
34+
35+
private final GherkinUtilsConfig gherkinSimpleConfig;
36+
37+
public GherkinUtilsFormatterFunc(GherkinUtilsConfig gherkinSimpleConfig) {
38+
this.gherkinSimpleConfig = gherkinSimpleConfig;
39+
}
40+
41+
// Follows https://github.com/cucumber/gherkin-utils/blob/main/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java
42+
private GherkinDocument parse(String gherkin) {
43+
GherkinParser parser = GherkinParser
44+
.builder()
45+
.includeSource(false)
46+
.build();
47+
return parser.parse(Envelope.of(new Source("test.feature", gherkin, SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN)))
48+
.findFirst()
49+
.orElseThrow(() -> new IllegalArgumentException("No envelope"))
50+
.getGherkinDocument()
51+
.orElseThrow(() -> new IllegalArgumentException("No gherkin document"));
52+
}
53+
54+
@Override
55+
public String apply(String inputString) {
56+
GherkinDocument gherkinDocument = parse(inputString);
57+
58+
return Pretty.prettyPrint(gherkinDocument, Syntax.gherkin);
59+
}
60+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 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.gherkin;
17+
18+
import java.io.Serializable;
19+
20+
public class GherkinUtilsConfig implements Serializable {
21+
private static final long serialVersionUID = 1L;
22+
23+
public static int defaultIndentSpaces() {
24+
// https://cucumber.io/docs/gherkin/reference/
25+
// Recommended indentation is 2 spaces
26+
return 2;
27+
}
28+
29+
final int indentSpaces;
30+
31+
public GherkinUtilsConfig(int indentSpaces) {
32+
this.indentSpaces = indentSpaces;
33+
}
34+
35+
public int getIndentSpaces() {
36+
return indentSpaces;
37+
}
38+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.gherkin;
17+
18+
import java.io.IOException;
19+
import java.io.Serializable;
20+
import java.lang.reflect.Constructor;
21+
import java.lang.reflect.InvocationTargetException;
22+
import java.util.Objects;
23+
24+
import com.diffplug.spotless.FormatterFunc;
25+
import com.diffplug.spotless.FormatterStep;
26+
import com.diffplug.spotless.JarState;
27+
import com.diffplug.spotless.Provisioner;
28+
29+
public class GherkinUtilsStep {
30+
private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-utils:";
31+
private static final String DEFAULT_VERSION = "8.0.2";
32+
33+
public static String defaultVersion() {
34+
return DEFAULT_VERSION;
35+
}
36+
37+
public static FormatterStep create(GherkinUtilsConfig gherkinSimpleConfig,
38+
String formatterVersion, Provisioner provisioner) {
39+
Objects.requireNonNull(provisioner, "provisioner cannot be null");
40+
return FormatterStep.createLazy("gherkin", () -> new GherkinUtilsStep.State(gherkinSimpleConfig, formatterVersion, provisioner), GherkinUtilsStep.State::toFormatter);
41+
}
42+
43+
private static final class State implements Serializable {
44+
private static final long serialVersionUID = 1L;
45+
46+
private final GherkinUtilsConfig gherkinSimpleConfig;
47+
private final JarState jarState;
48+
49+
private State(GherkinUtilsConfig gherkinSimpleConfig, String formatterVersion, Provisioner provisioner) throws IOException {
50+
this.gherkinSimpleConfig = gherkinSimpleConfig;
51+
this.jarState = JarState.from(MAVEN_COORDINATE + formatterVersion, provisioner);
52+
}
53+
54+
FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
55+
InstantiationException, IllegalAccessException {
56+
Class<?> formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gherkin.GherkinUtilsFormatterFunc");
57+
Constructor<?> constructor = formatterFunc.getConstructor(GherkinUtilsConfig.class);
58+
return (FormatterFunc) constructor.newInstance(gherkinSimpleConfig);
59+
}
60+
}
61+
62+
private GherkinUtilsStep() {
63+
// cannot be directly instantiated
64+
}
65+
}

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

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class CleanthatJavaStep {
4040
private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java";
4141

4242
// CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD
43-
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.6");
43+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.8");
4444

4545
// prevent direct instantiation
4646
private CleanthatJavaStep() {}
@@ -83,8 +83,8 @@ public static boolean defaultIncludeDraft() {
8383
public static FormatterStep create(String groupArtifact,
8484
String version,
8585
String sourceJdkVersion,
86-
List<String> excluded,
8786
List<String> included,
87+
List<String> excluded,
8888
boolean includeDraft,
8989
Provisioner provisioner) {
9090
Objects.requireNonNull(groupArtifact, "groupArtifact");
@@ -94,7 +94,7 @@ public static FormatterStep create(String groupArtifact,
9494
Objects.requireNonNull(version, "version");
9595
Objects.requireNonNull(provisioner, "provisioner");
9696
return FormatterStep.createLazy(NAME,
97-
() -> new JavaRefactorerState(NAME, groupArtifact, version, sourceJdkVersion, excluded, included, includeDraft, provisioner),
97+
() -> new JavaRefactorerState(NAME, groupArtifact, version, sourceJdkVersion, included, excluded, includeDraft, provisioner),
9898
JavaRefactorerState::createFormat);
9999
}
100100

@@ -120,7 +120,7 @@ static final class JavaRefactorerState implements Serializable {
120120
final boolean includeDraft;
121121

122122
JavaRefactorerState(String stepName, String version, Provisioner provisioner) throws IOException {
123-
this(stepName, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), defaultIncludeDraft(), provisioner);
123+
this(stepName, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultMutators(), defaultExcludedMutators(), defaultIncludeDraft(), provisioner);
124124
}
125125

126126
JavaRefactorerState(String stepName,
@@ -131,10 +131,7 @@ static final class JavaRefactorerState implements Serializable {
131131
List<String> excluded,
132132
boolean includeDraft,
133133
Provisioner provisioner) throws IOException {
134-
// https://github.com/diffplug/spotless/issues/1583
135-
if (!version.endsWith("-SNAPSHOT")) {
136-
JVM_SUPPORT.assertFormatterSupported(version);
137-
}
134+
JVM_SUPPORT.assertFormatterSupported(version);
138135
ModuleHelper.doOpenInternalPackagesIfRequired();
139136
this.jarState = JarState.from(groupArtifact + ":" + version, provisioner);
140137
this.stepName = stepName;
@@ -162,17 +159,9 @@ FormatterFunc createFormat() {
162159
throw new IllegalStateException("Issue executing the formatter", e);
163160
}
164161

165-
// https://github.com/diffplug/spotless/issues/1583
166-
if (!version.endsWith("-SNAPSHOT")) {
167-
return JVM_SUPPORT.suggestLaterVersionOnError(version, input -> {
168-
return (String) formatterMethod.invoke(formatter, input);
169-
});
170-
} else {
171-
return input -> {
172-
return (String) formatterMethod.invoke(formatter, input);
173-
};
174-
}
162+
return JVM_SUPPORT.suggestLaterVersionOnError(version, input -> {
163+
return (String) formatterMethod.invoke(formatter, input);
164+
});
175165
}
176-
177166
}
178167
}

0 commit comments

Comments
 (0)