Skip to content

Commit

Permalink
Update change logs and documentation for shell formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tcrawford-figure committed Jan 31, 2024
1 parent bc33de4 commit c2ae79b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Added
* `FileSignature.Promised` and `JarState.Promised` to facilitate round-trip serialization for the Gradle configuration cache. ([#1945](https://github.com/diffplug/spotless/pull/1945))
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))

### Removed
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
* **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954))
Expand Down
3 changes: 3 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Fixed
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))

### Added
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))

## [6.25.0] - 2024-01-23
### Added
* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#2009](https://github.com/diffplug/spotless/pull/2009))
Expand Down
6 changes: 5 additions & 1 deletion plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ spotless {
```gradle
spotless {
shell {
target 'scripts/**/*.sh' // default: '*.sh'
target 'scripts/**/*.sh' // default: '**/*.sh'
shfmt() // has its own section below
}
Expand All @@ -1003,11 +1003,15 @@ spotless {
[homepage](https://github.com/mvdan/sh). [changelog](https://github.com/mvdan/sh/blob/master/CHANGELOG.md).
When formatting shell scripts via `shfmt`, configure `shfmt` settings via `.editorconfig`.
Refer to the `shfmt` man page for `.editorconfig` settings.
```gradle
shfmt('3.7.0') // version is optional
// if shfmt is not on your path, you must specify its location manually
shfmt().pathToExe('/opt/homebrew/bin/shfmt')
// Spotless always checks the version of the shfmt it is using
// and will fail with an error if it does not match the expected version
// (whether manually specified or default). If there is a problem, Spotless
Expand Down
3 changes: 3 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Fixed
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))

### Added
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))

## [2.43.0] - 2024-01-23
### Added
* Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/issues/1998))
Expand Down
31 changes: 30 additions & 1 deletion plugin-maven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,40 @@ Uses Jackson and YAMLFactory to pretty print objects:
</jackson>
```

## Shell

- `com.diffplug.spotless.maven.FormatterFactory.addStepFactory(FormatterStepFactory)` [code](./src/main/java/com/diffplug/spotless/maven/shell/Shell.java)

```xml
<configuration>
<shell>
<includes> <!-- Not required. Defaults to **/*.sh -->
<include>scripts/**/*.sh</include>
</includes>

<shfmt /> <!-- has its own section below -->
</shell>
</configuration>
```

### shfmt

[homepage](https://github.com/mvdan/sh). [changelog](https://github.com/mvdan/sh/blob/master/CHANGELOG.md).

When formatting shell scripts via `shfmt`, configure `shfmt` settings via `.editorconfig`.

```xml
<shfmt>
<version>3.7.0</version> <!-- optional: Custom version of 'mvdan/sh' -->
<pathToExe>/opt/homebrew/bin/shfmt</pathToExe> <!-- optional: if shfmt is not on your path, you must specify its location manually -->
</shfmt>
```

## Gherkin

- `com.diffplug.spotless.maven.FormatterFactory.addStepFactory(FormatterStepFactory)` [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java)

```gradle
```xml
<configuration>
<gherkin>
<includes> <!-- You have to set the target manually -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.diffplug.spotless.maven.shell;

import java.util.Collections;
import java.util.Set;

import org.apache.maven.project.MavenProject;
Expand All @@ -30,9 +29,11 @@
* and shell-specific (e.g. {@link Shfmt}) steps.
*/
public class Shell extends FormatterFactory {
private static final Set<String> DEFAULT_INCLUDES = Set.of("**/*.sh");

@Override
public Set<String> defaultIncludes(MavenProject project) {
return Collections.emptySet();
return DEFAULT_INCLUDES;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.diffplug.spotless.shell.ShfmtStep;

public class Shfmt implements FormatterStepFactory {

@Parameter
private String version;

Expand Down

0 comments on commit c2ae79b

Please sign in to comment.