Skip to content

Commit 0f36d0f

Browse files
authored
Merge branch 'main' into tylercrawford/issue-1567/support-sh-bash
2 parents 6ebed55 + 350cf2e commit 0f36d0f

File tree

27 files changed

+474
-147
lines changed

27 files changed

+474
-147
lines changed

Diff for: CHANGES.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Added
1414
* New static method to `DiffMessageFormatter` which allows to retrieve diffs with their line numbers ([#1960](https://github.com/diffplug/spotless/issues/1960))
15-
* Gradle support for shell via [shfmt](https://github.com/mvdan/sh). ([#1994](https://github.com/diffplug/spotless/pull/1994))
15+
* Format shell via [shfmt](https://github.com/mvdan/sh). ([#1994](https://github.com/diffplug/spotless/pull/1994))
16+
### Fixed
17+
* Fix empty files with biome >= 1.5.0 when formatting files that are in the ignore list of the biome configuration file. ([#1989](https://github.com/diffplug/spotless/pull/1989) fixes [#1987](https://github.com/diffplug/spotless/issues/1987))
18+
* Fix a regression in BufStep where the same arguments were being provided to every `buf` invocation. ([#1976](https://github.com/diffplug/spotless/issues/1976))
1619
### Changes
1720
* Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948))
21+
* Bump default `ktlint` version to latest `1.0.1` -> `1.1.1`. ([#1973](https://github.com/diffplug/spotless/pull/1973))
22+
* Bump default `googleJavaFormat` version to latest `1.18.1` -> `1.19.2`. ([#1971](https://github.com/diffplug/spotless/pull/1971))
23+
* Bump default `diktat` version to latest `1.2.5` -> `2.0.0`. ([#1972](https://github.com/diffplug/spotless/pull/1972))
1824

1925
## [2.43.1] - 2023-12-04
2026
### Fixed

Diff for: CONTRIBUTING.md

+20
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,26 @@ The gist of it is that you will have to:
151151

152152
If you get something running, we'd love to host your plugin within this repo as a peer to `plugin-gradle` and `plugin-maven`.
153153

154+
## Run tests
155+
156+
To run all tests, simply do
157+
158+
> gradlew test
159+
160+
Since that takes some time, you might only want to run the tests
161+
concerning what you are working on:
162+
163+
```shell
164+
# Run only from test from the "lib" project
165+
gradlew :testlib:test --tests com.diffplug.spotless.generic.IndentStepTest
166+
167+
# Run only one test from the "plugin-maven" project
168+
gradlew :plugin-maven:test --tests com.diffplug.spotless.maven.pom.SortPomMavenTest
169+
170+
# Run only one test from the "plugin-gradle" project
171+
gradlew :plugin-gradle:test --tests com.diffplug.gradle.spotless.FreshMarkExtensionTest
172+
```
173+
154174
## Integration testing
155175

156176
### Gradle - locally

Diff for: lib/build.gradle

+12-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ versionCompatibility {
5252
]
5353
targetSourceSetName = 'ktlint'
5454
}
55+
namespaces.register('Diktat') {
56+
versions = [
57+
'1.2.5',
58+
'2.0.0',
59+
]
60+
targetSourceSetName = 'diktat'
61+
}
5562
}
5663
}
5764

@@ -76,15 +83,17 @@ dependencies {
7683
String VER_CLEANTHAT='2.17'
7784
cleanthatCompileOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT"
7885
compatCleanthat2Dot1CompileAndTestOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT"
79-
// diktat
80-
diktatCompileOnly 'org.cqfn.diktat:diktat-rules:1.2.5'
86+
// diktat old supported version 1.x
87+
compatDiktat1Dot2Dot5CompileOnly "org.cqfn.diktat:diktat-rules:1.2.5"
88+
// diktat latest supported version 2.x
89+
compatDiktat2Dot0Dot0CompileOnly "com.saveourtool.diktat:diktat-runner:2.0.0"
8190
// flexmark
8291
flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.64.0'
8392
// gherkin
8493
gherkinCompileOnly 'io.cucumber:gherkin-utils:8.0.2'
8594
gherkinCompileOnly 'org.slf4j:slf4j-api:2.0.0'
8695
// googleJavaFormat
87-
googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.18.1'
96+
googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.19.2'
8897
// gson
8998
gsonCompileOnly 'com.google.code.gson:gson:2.10.1'
9099
// jackson
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.diktat.compat;
17+
18+
import java.io.File;
19+
import java.util.ArrayList;
20+
import java.util.Collections;
21+
import java.util.List;
22+
23+
import javax.annotation.Nullable;
24+
25+
import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider;
26+
27+
import com.pinterest.ktlint.core.KtLint;
28+
import com.pinterest.ktlint.core.LintError;
29+
import com.pinterest.ktlint.core.RuleSet;
30+
import com.pinterest.ktlint.core.api.EditorConfigOverride;
31+
32+
import kotlin.Unit;
33+
import kotlin.jvm.functions.Function2;
34+
35+
public class DiktatCompat1Dot2Dot5Adapter implements DiktatCompatAdapter {
36+
private final List<RuleSet> ruleSets;
37+
private final Function2<? super LintError, ? super Boolean, Unit> formatterCallback;
38+
private final ArrayList<LintError> errors = new ArrayList<>();
39+
40+
public DiktatCompat1Dot2Dot5Adapter(@Nullable File configFile) {
41+
if (configFile != null) {
42+
System.setProperty("diktat.config.path", configFile.getAbsolutePath());
43+
}
44+
this.ruleSets = Collections.singletonList(new DiktatRuleSetProvider().get());
45+
this.formatterCallback = new FormatterCallback(errors);
46+
}
47+
48+
static class FormatterCallback implements Function2<LintError, Boolean, Unit> {
49+
private final ArrayList<LintError> errors;
50+
51+
FormatterCallback(ArrayList<LintError> errors) {
52+
this.errors = errors;
53+
}
54+
55+
@Override
56+
public Unit invoke(LintError lintError, Boolean corrected) {
57+
if (!corrected) {
58+
errors.add(lintError);
59+
}
60+
return null;
61+
}
62+
}
63+
64+
@Override
65+
public String format(final File file, final String content, final boolean isScript) {
66+
errors.clear();
67+
String result = KtLint.INSTANCE.format(new KtLint.ExperimentalParams(
68+
// Unlike Ktlint, Diktat requires full path to the file.
69+
// See https://github.com/diffplug/spotless/issues/1189, https://github.com/analysis-dev/diktat/issues/1202
70+
file.getAbsolutePath(),
71+
content,
72+
ruleSets,
73+
Collections.emptyMap(),
74+
formatterCallback,
75+
isScript,
76+
null,
77+
false,
78+
new EditorConfigOverride(),
79+
false));
80+
81+
DiktatReporting.reportIfRequired(errors, LintError::getLine, LintError::getCol, LintError::getDetail);
82+
83+
return result;
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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.diktat.compat;
17+
18+
import java.io.File;
19+
import java.io.FileInputStream;
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.util.ArrayList;
23+
import java.util.Collections;
24+
import java.util.List;
25+
26+
import org.jetbrains.annotations.NotNull;
27+
import org.jetbrains.annotations.Nullable;
28+
29+
import com.saveourtool.diktat.DiktatFactoriesKt;
30+
import com.saveourtool.diktat.DiktatProcessor;
31+
import com.saveourtool.diktat.api.DiktatCallback;
32+
import com.saveourtool.diktat.api.DiktatError;
33+
import com.saveourtool.diktat.api.DiktatRuleConfig;
34+
import com.saveourtool.diktat.api.DiktatRuleSet;
35+
36+
import kotlin.Unit;
37+
38+
public class DiktatCompat2Dot0Dot0Adapter implements DiktatCompatAdapter {
39+
private final DiktatProcessor processor;
40+
private final DiktatCallback formatterCallback;
41+
private final ArrayList<DiktatError> errors = new ArrayList<>();
42+
43+
public DiktatCompat2Dot0Dot0Adapter(@Nullable File configFile) {
44+
this.processor = getDiktatReporter(configFile);
45+
this.formatterCallback = new FormatterCallback(errors);
46+
}
47+
48+
@Override
49+
public String format(File file, String content, boolean isScript) {
50+
errors.clear();
51+
String result = processor.fix(content, file.toPath(), formatterCallback);
52+
DiktatReporting.reportIfRequired(errors, DiktatError::getLine, DiktatError::getCol, DiktatError::getDetail);
53+
return result;
54+
}
55+
56+
private static class FormatterCallback implements DiktatCallback {
57+
private final ArrayList<DiktatError> errors;
58+
59+
FormatterCallback(ArrayList<DiktatError> errors) {
60+
this.errors = errors;
61+
}
62+
63+
@Override
64+
public Unit invoke(DiktatError diktatError, Boolean corrected) {
65+
doInvoke(diktatError, corrected);
66+
return Unit.INSTANCE;
67+
}
68+
69+
@Override
70+
public void invoke(@NotNull DiktatError diktatError, boolean corrected) {
71+
doInvoke(diktatError, corrected);
72+
}
73+
74+
private void doInvoke(@NotNull DiktatError diktatError, boolean corrected) {
75+
if (!corrected) {
76+
errors.add(diktatError);
77+
}
78+
}
79+
}
80+
81+
private static DiktatProcessor getDiktatReporter(File configFile) {
82+
final DiktatRuleSet ruleSet = DiktatFactoriesKt.getDiktatRuleSetFactory().invoke(readRuleConfigs(configFile));
83+
return DiktatFactoriesKt.getDiktatProcessorFactory().invoke(ruleSet);
84+
}
85+
86+
private static List<DiktatRuleConfig> readRuleConfigs(File configFile) {
87+
if (configFile == null) {
88+
return Collections.emptyList();
89+
}
90+
try (final InputStream configInputStream = new FileInputStream(configFile)) {
91+
return DiktatFactoriesKt.getDiktatRuleConfigReader().invoke(configInputStream);
92+
} catch (IOException e) {
93+
throw new IllegalArgumentException("Fail to read configFile", e);
94+
}
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.diktat.compat;
17+
18+
import java.io.File;
19+
20+
public interface DiktatCompatAdapter {
21+
String format(File file, String content, boolean isScript);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.diktat.compat;
17+
18+
import java.util.List;
19+
import java.util.function.Function;
20+
import java.util.function.ToIntFunction;
21+
22+
interface DiktatReporting {
23+
static <T> void reportIfRequired(
24+
List<T> errors,
25+
ToIntFunction<T> lineGetter,
26+
ToIntFunction<T> columnGetter,
27+
Function<T, String> detailGetter) {
28+
if (!errors.isEmpty()) {
29+
StringBuilder error = new StringBuilder();
30+
error.append("There are ").append(errors.size()).append(" unfixed errors:");
31+
for (T er : errors) {
32+
error.append(System.lineSeparator())
33+
.append("Error on line: ").append(lineGetter.applyAsInt(er))
34+
.append(", column: ").append(columnGetter.applyAsInt(er))
35+
.append(" cannot be fixed automatically")
36+
.append(System.lineSeparator())
37+
.append(detailGetter.apply(er));
38+
}
39+
throw new AssertionError(error);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)