Skip to content

Commit de6d184

Browse files
committed
Merge remote-tracking branch 'upstream/main' into petertrr/add-gofmt#861
# Conflicts: # CHANGES.md # plugin-maven/CHANGES.md # plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java
2 parents d3f7680 + 409902d commit de6d184

File tree

11 files changed

+149
-12
lines changed

11 files changed

+149
-12
lines changed

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ This document is intended for Spotless developers.
1010
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
1111

1212
## [Unreleased]
13+
### Added
14+
* Maven - Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/pull/1998))
1315
* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/issues/2001))
1416

1517
## [2.44.0] - 2024-01-15
1618
### Added
1719
* New static method to `DiffMessageFormatter` which allows to retrieve diffs with their line numbers ([#1960](https://github.com/diffplug/spotless/issues/1960))
18-
* Format shell via [shfmt](https://github.com/mvdan/sh). ([#1994](https://github.com/diffplug/spotless/pull/1994))
20+
* Gradle - Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1994](https://github.com/diffplug/spotless/pull/1994))
1921
### Fixed
2022
* 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))
2123
* Fix a regression in BufStep where the same arguments were being provided to every `buf` invocation. ([#1976](https://github.com/diffplug/spotless/issues/1976))

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ lib('pom.SortPomStepStep') +'{{no}} | {{yes}}
104104
lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
105105
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
106106
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
107-
lib('shell.ShfmtStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
107+
lib('shell.ShfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
108108
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
109109
extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
110110
lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -158,7 +158,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
158158
| [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
159159
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
160160
| [`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: | :white_large_square: | :white_large_square: | :white_large_square: |
161+
| [`shell.ShfmtStep`](lib/src/main/java/com/diffplug/spotless/shell/ShfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
162162
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
163163
| [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
164164
| [`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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.adarshr.test-logger'
2+
3+
// See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations
24
def special = [
35
'Black',
46
'Buf',
@@ -10,10 +12,6 @@ def special = [
1012

1113
boolean isCiServer = System.getenv().containsKey("CI")
1214
tasks.withType(Test).configureEach {
13-
// See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations
14-
useJUnitPlatform {
15-
excludeTags special as String[]
16-
}
1715
if (isCiServer) {
1816
retry {
1917
maxRetries = 2
@@ -27,7 +25,11 @@ tasks.withType(Test).configureEach {
2725
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
2826
}
2927
}
30-
28+
tasks.named('test').configure {
29+
useJUnitPlatform {
30+
excludeTags special as String[]
31+
}
32+
}
3133
special.forEach { tag ->
3234
tasks.register("test${tag}", Test) {
3335
useJUnitPlatform { includeTags tag }

plugin-gradle/CHANGES.md

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

88
## [6.24.0] - 2024-01-15
99
### Added
10-
* Support for shell via [shfmt](https://github.com/mvdan/sh).
10+
* Support for shell formatting via [shfmt](https://github.com/mvdan/sh). ([#1994](https://github.com/diffplug/spotless/pull/1994))
1111
### Fixed
12-
* 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))=======
12+
* 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))
1313
* Fix a regression in BufStep where the same arguments were being provided to every `buf` invocation. ([#1976](https://github.com/diffplug/spotless/issues/1976))
1414
### Changes
1515
* Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948))

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ShfmtIntegrationTest.java renamed to plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ShellExtensionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.diffplug.spotless.tag.ShfmtTest;
2323

2424
@ShfmtTest
25-
public class ShfmtIntegrationTest extends GradleIntegrationHarness {
25+
public class ShellExtensionTest extends GradleIntegrationHarness {
2626
@Test
2727
void shfmt() throws IOException {
2828
setFile("build.gradle").toLines(

plugin-maven/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
44

55
## [Unreleased]
6+
### Added
7+
* Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/issues/1998))
68
* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/issues/2001))
79

810
## [2.42.0] - 2024-01-15

plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.diffplug.spotless.maven.pom.Pom;
7575
import com.diffplug.spotless.maven.python.Python;
7676
import com.diffplug.spotless.maven.scala.Scala;
77+
import com.diffplug.spotless.maven.shell.Shell;
7778
import com.diffplug.spotless.maven.sql.Sql;
7879
import com.diffplug.spotless.maven.typescript.Typescript;
7980
import com.diffplug.spotless.maven.yaml.Yaml;
@@ -179,6 +180,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
179180
@Parameter
180181
private Json json;
181182

183+
@Parameter
184+
private Shell shell;
185+
182186
@Parameter
183187
private Yaml yaml;
184188

@@ -362,7 +366,7 @@ private FileLocator getFileLocator() {
362366
}
363367

364368
private List<FormatterFactory> getFormatterFactories() {
365-
return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, javascript, antlr4, pom, sql, python, markdown, json, yaml, gherkin, go))
369+
return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, javascript, antlr4, pom, sql, python, markdown, json, shell, yaml, gherkin, go))
366370
.filter(Objects::nonNull)
367371
.collect(toList());
368372
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2024 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.maven.shell;
17+
18+
import java.util.Collections;
19+
import java.util.Set;
20+
21+
import org.apache.maven.project.MavenProject;
22+
23+
import com.diffplug.spotless.maven.FormatterFactory;
24+
import com.diffplug.spotless.maven.generic.LicenseHeader;
25+
26+
/**
27+
* A {@link FormatterFactory} implementation that corresponds to {@code <shell>...</shell>} configuration element.
28+
* <p>
29+
* It defines a formatter for shell source files that can execute both language agnostic (e.g. {@link LicenseHeader})
30+
* and shell-specific (e.g. {@link Shfmt}) steps.
31+
*/
32+
public class Shell extends FormatterFactory {
33+
@Override
34+
public Set<String> defaultIncludes(MavenProject project) {
35+
return Collections.emptySet();
36+
}
37+
38+
@Override
39+
public String licenseHeaderDelimiter() {
40+
return null;
41+
}
42+
43+
public void addShfmt(Shfmt shfmt) {
44+
addStepFactory(shfmt);
45+
}
46+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 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.maven.shell;
17+
18+
import org.apache.maven.plugins.annotations.Parameter;
19+
20+
import com.diffplug.spotless.FormatterStep;
21+
import com.diffplug.spotless.maven.FormatterStepConfig;
22+
import com.diffplug.spotless.maven.FormatterStepFactory;
23+
import com.diffplug.spotless.shell.ShfmtStep;
24+
25+
public class Shfmt implements FormatterStepFactory {
26+
27+
@Parameter
28+
private String version;
29+
30+
@Parameter
31+
private String pathToExe;
32+
33+
@Override
34+
public FormatterStep newFormatterStep(FormatterStepConfig config) {
35+
ShfmtStep shfmt = ShfmtStep.withVersion(version == null ? ShfmtStep.defaultVersion() : version);
36+
if (pathToExe != null) {
37+
shfmt = shfmt.withPathToExe(pathToExe);
38+
}
39+
return shfmt.create();
40+
}
41+
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ protected void writePomWithJsonSteps(String... steps) throws IOException {
179179
writePom(groupWithSteps("json", including("**/*.json"), steps));
180180
}
181181

182+
protected void writePomWithShellSteps(String... steps) throws IOException {
183+
writePom(groupWithSteps("shell", including("**/*.sh"), steps));
184+
}
185+
182186
protected void writePomWithYamlSteps(String... steps) throws IOException {
183187
writePom(groupWithSteps("yaml", including("**/*.yaml"), steps));
184188
}

0 commit comments

Comments
 (0)