Skip to content

Commit d102709

Browse files
committed
merge main (DiktatStep conflict)
2 parents ce34f89 + e62f9cd commit d102709

File tree

61 files changed

+1721
-240
lines changed

Some content is hidden

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

61 files changed

+1721
-240
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ gradle-app.setting
1919
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
2020
!gradle-wrapper.jar
2121

22-
#Gradle-Lock files in _ext just serving as an input for lib-extra
23-
_ext/*/gradle/dependency-locks/*.lockfile
24-
2522
### Eclipse ###
2623
.metadata
2724
.gradle

CHANGES.md

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

1212
## [Unreleased]
1313
### Added
14+
* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/pull/2001))
15+
* Support for formatting Java Docs for the Palantir formatter ([#2009](https://github.com/diffplug/spotless/pull/2009))
16+
17+
## [2.44.0] - 2024-01-15
18+
### Added
1419
* New static method to `DiffMessageFormatter` which allows to retrieve diffs with their line numbers ([#1960](https://github.com/diffplug/spotless/issues/1960))
20+
* Gradle - Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1994](https://github.com/diffplug/spotless/pull/1994))
21+
### Fixed
22+
* 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))
23+
* Fix a regression in BufStep where the same arguments were being provided to every `buf` invocation. ([#1976](https://github.com/diffplug/spotless/issues/1976))
1524
### Changes
1625
* Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948))
26+
* Bump default `ktlint` version to latest `1.0.1` -> `1.1.1`. ([#1973](https://github.com/diffplug/spotless/pull/1973))
27+
* Bump default `googleJavaFormat` version to latest `1.18.1` -> `1.19.2`. ([#1971](https://github.com/diffplug/spotless/pull/1971))
28+
* Bump default `diktat` version to latest `1.2.5` -> `2.0.0`. ([#1972](https://github.com/diffplug/spotless/pull/1972))
1729

1830
## [2.43.1] - 2023-12-04
1931
### Fixed

CONTRIBUTING.md

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ For the folders below in monospace text, they are published on MavenCentral at t
3636
| `lib-extra` | Contains the optional parts of Spotless which require external dependencies. `LineEnding.GIT_ATTRIBUTES` won't work unless `lib-extra` is available. |
3737
| `plugin-gradle` | Integrates spotless and all of its formatters into Gradle. |
3838
| `plugin-maven` | Integrates spotless and all of its formatters into Maven. |
39-
| `_ext` | Folder for generating glue jars (specifically packaging Eclipse jars from p2 for consumption using maven).
4039

4140
## How to add a new FormatterStep
4241

@@ -140,24 +139,6 @@ There are many great formatters (prettier, clang-format, black, etc.) which live
140139

141140
Because of Spotless' up-to-date checking and [git ratcheting](https://github.com/diffplug/spotless/tree/main/plugin-gradle#ratchet), Spotless actually doesn't have to call formatters very often, so even an expensive shell call for every single invocation isn't that bad. Anything that works is better than nothing, and we can always speed things up later if it feels too slow (but it probably won't).
142141

143-
## How to enable the `_ext` projects
144-
145-
The `_ext` projects are disabled per default, since:
146-
147-
* some of the projects perform vast downloads at configuration time
148-
* the downloaded content may change on server side and break CI builds
149-
150-
151-
The `_ext` can be activated via the root project property `com.diffplug.spotless.include.ext`.
152-
153-
Activate the property via command line, like for example:
154-
155-
```
156-
gradlew -Pcom.diffplug.spotless.include.ext=true build
157-
```
158-
159-
Or set the property in your user `gradle.properties` file, which is especially recommended if you like to work with the `_ext` projects using IDEs.
160-
161142
## How to add a new plugin for a build system
162143

163144
The gist of it is that you will have to:
@@ -172,6 +153,37 @@ The gist of it is that you will have to:
172153

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

156+
## Run tests
157+
158+
To run all tests, simply do
159+
160+
> gradlew test
161+
162+
Since that takes some time, you might only want to run the tests
163+
concerning what you are working on:
164+
165+
```shell
166+
# Run only from test from the "lib" project
167+
gradlew :testlib:test --tests com.diffplug.spotless.generic.IndentStepTest
168+
169+
# Run only one test from the "plugin-maven" project
170+
gradlew :plugin-maven:test --tests com.diffplug.spotless.maven.pom.SortPomMavenTest
171+
172+
# Run only one test from the "plugin-gradle" project
173+
gradlew :plugin-gradle:test --tests com.diffplug.gradle.spotless.FreshMarkExtensionTest
174+
```
175+
176+
## Check and format code
177+
178+
Before creating a pull request, you might want to format (yes, spotless is formatted by spotless)
179+
the code and check for possible bugs
180+
181+
* `./gradlew spotlessApply`
182+
* `./gradlew spotbugsMain`
183+
184+
These checks are also run by the automated pipeline when you submit a pull request, if
185+
the pipeline fails, first check if the code is formatted and no bugs were found.
186+
175187
## Integration testing
176188

177189
### Gradle - locally

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Maven Plugin](https://img.shields.io/maven-central/v/com.diffplug.spotless/spotless-maven-plugin?color=blue&label=maven%20plugin)](plugin-maven)
55
[![SBT Plugin](https://img.shields.io/badge/sbt%20plugin-0.1.3-blue)](https://github.com/moznion/sbt-spotless)
66

7-
Spotless can format <antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | sql | typeScript | vue | yaml | anything> using <gradle | maven | sbt | anything>.
7+
Spotless can format <antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | shell | sql | typeScript | vue | yaml | anything> using <gradle | maven | sbt | anything>.
88

99
You probably want one of the links below:
1010

@@ -75,8 +75,10 @@ lib('generic.ReplaceRegexStep') +'{{yes}} | {{yes}}
7575
lib('generic.ReplaceStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7676
lib('generic.TrimTrailingWhitespaceStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7777
lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
78+
lib('biome.BiomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7879
lib('cpp.ClangFormatStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
7980
extra('cpp.EclipseFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
81+
lib('go.GofmtFormatStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
8082
lib('gherkin.GherkinUtilsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
8183
extra('groovy.GrEclipseFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
8284
lib('java.GoogleJavaFormatStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
@@ -101,8 +103,8 @@ lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}}
101103
lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
102104
lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
103105
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
104-
lib('biome.BiomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
105106
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
107+
lib('shell.ShfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
106108
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
107109
extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
108110
lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -127,8 +129,10 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
127129
| [`generic.ReplaceStep`](lib/src/main/java/com/diffplug/spotless/generic/ReplaceStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
128130
| [`generic.TrimTrailingWhitespaceStep`](lib/src/main/java/com/diffplug/spotless/generic/TrimTrailingWhitespaceStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
129131
| [`antlr4.Antlr4FormatterStep`](lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
132+
| [`biome.BiomeStep`](lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
130133
| [`cpp.ClangFormatStep`](lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
131134
| [`cpp.EclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
135+
| [`go.GofmtFormatStep`](lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
132136
| [`gherkin.GherkinUtilsStep`](lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
133137
| [`groovy.GrEclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
134138
| [`java.GoogleJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
@@ -153,8 +157,8 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
153157
| [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
154158
| [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
155159
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
156-
| [`biome.BiomeStep`](lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
157160
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
161+
| [`shell.ShfmtStep`](lib/src/main/java/com/diffplug/spotless/shell/ShfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
158162
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
159163
| [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
160164
| [`yaml.JacksonYamlStep`](lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |

gradle/special-tests.gradle

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
apply plugin: 'com.adarshr.test-logger'
2+
3+
// See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations
24
def special = [
3-
'Npm',
45
'Black',
6+
'Buf',
57
'Clang',
6-
'Buf'
8+
'gofmt',
9+
'Npm',
10+
'Shfmt'
711
]
812

913
boolean isCiServer = System.getenv().containsKey("CI")
1014
tasks.withType(Test).configureEach {
11-
// See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations
12-
useJUnitPlatform {
13-
excludeTags special as String[]
14-
}
1515
if (isCiServer) {
1616
retry {
1717
maxRetries = 2
@@ -25,7 +25,11 @@ tasks.withType(Test).configureEach {
2525
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
2626
}
2727
}
28-
28+
tasks.named('test').configure {
29+
useJUnitPlatform {
30+
excludeTags special as String[]
31+
}
32+
}
2933
special.forEach { tag ->
3034
tasks.register("test${tag}", Test) {
3135
useJUnitPlatform { includeTags tag }

lib/build.gradle

Lines changed: 12 additions & 3 deletions
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+
}

0 commit comments

Comments
 (0)