Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/update_renovate_changelogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
("libraries", "diktat-runner"): "diktat",
("libraries", "flexmark-all"): "flexmark",
("libraries", "freshmark"): "freshmark",
("libraries", "gherkin-utils"): "gherkin-utils",
("libraries", "gherkin-formatter"): "gherkin-formatter",
("libraries", "google-java-format"): "google-java-format",
("libraries", "gson"): "gson",
("libraries", "json-simple"): "json-simple",
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Fixed
- Fix npm/node executable discovery treating a directory (e.g. an `npm` folder inside `NODE_PATH`) as an executable. ([#3190](https://github.com/diffplug/spotless/issues/3190))

### Changes
- Replace `gherkin-utils` with `gherkin-formatter`. ([#3217](https://github.com/diffplug/spotless/issues/3217))

## [4.12.0] - 2026-11-21
### Changes
- Bump default `adocfmt` version `0.3.1` -> `0.3.2`. ([#3180](https://github.com/diffplug/spotless/pull/3180))
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ diktat-runner = "com.saveourtool.diktat:diktat-runner:2.0.0"
flexmark-all = "com.vladsch.flexmark:flexmark-all:0.64.8"
freshmark = "com.diffplug.freshmark:freshmark:1.3.1"
cucumber-gherkin = "io.cucumber:gherkin:43.0.0"
gherkin-utils = "io.cucumber:gherkin-utils:12.0.2"
gherkin-formatter = "io.cucumber:gherkin-formatter:0.1.0"
google-java-format = "com.google.googlejavaformat:google-java-format:2.0.0"
gson = "com.google.code.gson:gson:2.15.0"
json-simple = "org.json:json:20210307"
Expand Down
4 changes: 2 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ buildConfig {
buildConfigField("VERSION_ADOCFMT", libs.adocfmt.version)
}
forClass("com.diffplug.spotless.gherkin", "GherkinBuildConfig") {
buildConfigField("VERSION_GHERKIN_UTILS", libs.gherkin.utils.version)
buildConfigField("VERSION_GHERKIN_FORMATTER", libs.gherkin.formatter.version)
buildConfigField("VERSION_GHERKIN", libs.cucumber.gherkin.version)
}
forClass("com.diffplug.spotless.json", "JsonBuildConfig") {
Expand Down Expand Up @@ -149,7 +149,7 @@ dependencies {
// flexmark
"flexmarkCompileOnly"(libs.flexmark.all)
// gherkin
"gherkinCompileOnly"(libs.gherkin.utils)
"gherkinCompileOnly"(libs.gherkin.formatter)
"gherkinCompileOnly"(libs.cucumber.gherkin)
"gherkinCompileOnly"(libs.slf4j.api)
// googleJavaFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,33 @@
import org.slf4j.LoggerFactory;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.gherkin.GherkinUtilsConfig;
import com.diffplug.spotless.gherkin.GherkinFormatterConfig;

import io.cucumber.gherkin.GherkinParser;
import io.cucumber.gherkin.utils.pretty.Pretty;
import io.cucumber.gherkin.utils.pretty.Syntax;
import io.cucumber.gherkin.formatter.GherkinDocumentFormatter;
import io.cucumber.messages.types.Envelope;
import io.cucumber.messages.types.GherkinDocument;
import io.cucumber.messages.types.Source;
import io.cucumber.messages.types.SourceMediaType;

public class GherkinUtilsFormatterFunc implements FormatterFunc {
private static final Logger LOGGER = LoggerFactory.getLogger(GherkinUtilsFormatterFunc.class);
public class GherkinFormatterFormatterFunc implements FormatterFunc {
private static final Logger LOGGER = LoggerFactory.getLogger(GherkinFormatterFormatterFunc.class);

private final GherkinUtilsConfig gherkinSimpleConfig;
private final GherkinDocumentFormatter formatter;

public GherkinUtilsFormatterFunc(GherkinUtilsConfig gherkinSimpleConfig) {
this.gherkinSimpleConfig = gherkinSimpleConfig;
public GherkinFormatterFormatterFunc(GherkinFormatterConfig gherkinSimpleConfig) {
this.formatter = GherkinDocumentFormatter.builder()
.indentation(" ".repeat(gherkinSimpleConfig.getIndentSpaces()))
.build();
;
}

// Follows https://github.com/cucumber/gherkin-utils/blob/main/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java
// Follows https://github.com/cucumber/gherkin-formatter/tree/main/java#usage
private GherkinDocument parse(String gherkin) {
GherkinParser parser = GherkinParser
.builder()
.includeSource(false)
.includePickles(false)
.build();
return parser.parse(Envelope.of(new Source("test.feature", gherkin, SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN)))
.findFirst()
Expand All @@ -53,8 +56,6 @@ private GherkinDocument parse(String gherkin) {

@Override
public String apply(String inputString) {
GherkinDocument gherkinDocument = parse(inputString);

return Pretty.prettyPrint(gherkinDocument, Syntax.gherkin);
return formatter.format(parse(inputString));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2025 DiffPlug
* Copyright 2023-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@
import java.io.Serial;
import java.io.Serializable;

public class GherkinUtilsConfig implements Serializable {
public class GherkinFormatterConfig implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

Expand All @@ -30,7 +30,7 @@ public static int defaultIndentSpaces() {

final int indentSpaces;

public GherkinUtilsConfig(int indentSpaces) {
public GherkinFormatterConfig(int indentSpaces) {
this.indentSpaces = indentSpaces;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@
import com.diffplug.spotless.JarState;
import com.diffplug.spotless.Provisioner;

public final class GherkinUtilsStep implements Serializable {
public final class GherkinFormatterStep implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-utils:";
private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-formatter:";
private static final String GHERKIN_MAVEN_COORDINATE = "io.cucumber:gherkin:";
public static final String NAME = "gherkinUtils";
public static final String NAME = "gherkinFormatter";

private final JarState.Promised jarState;
private final GherkinUtilsConfig gherkinSimpleConfig;
private final GherkinFormatterConfig gherkinSimpleConfig;

private GherkinUtilsStep(JarState.Promised jarState, GherkinUtilsConfig gherkinSimpleConfig) {
private GherkinFormatterStep(JarState.Promised jarState, GherkinFormatterConfig gherkinSimpleConfig) {
this.jarState = jarState;
this.gherkinSimpleConfig = gherkinSimpleConfig;
}

public static String defaultVersion() {
return GherkinBuildConfig.VERSION_GHERKIN_UTILS;
return GherkinBuildConfig.VERSION_GHERKIN_FORMATTER;
}

public static FormatterStep create(GherkinUtilsConfig gherkinSimpleConfig,
public static FormatterStep create(GherkinFormatterConfig gherkinSimpleConfig,
String formatterVersion, Provisioner provisioner) {
Objects.requireNonNull(provisioner, "provisioner cannot be null");
List<String> coordinates = List.of(
MAVEN_COORDINATE + formatterVersion,
GHERKIN_MAVEN_COORDINATE + GherkinBuildConfig.VERSION_GHERKIN);
return FormatterStep.create(NAME,
new GherkinUtilsStep(JarState.promise(() -> JarState.from(coordinates, provisioner)), gherkinSimpleConfig),
GherkinUtilsStep::equalityState,
GherkinUtilsStep.State::toFormatter);
new GherkinFormatterStep(JarState.promise(() -> JarState.from(coordinates, provisioner)), gherkinSimpleConfig),
GherkinFormatterStep::equalityState,
GherkinFormatterStep.State::toFormatter);
}

private State equalityState() {
Expand All @@ -66,18 +66,18 @@ private static final class State implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

private final GherkinUtilsConfig gherkinSimpleConfig;
private final GherkinFormatterConfig gherkinSimpleConfig;
private final JarState jarState;

State(JarState jarState, GherkinUtilsConfig gherkinSimpleConfig) {
State(JarState jarState, GherkinFormatterConfig gherkinSimpleConfig) {
this.jarState = jarState;
this.gherkinSimpleConfig = gherkinSimpleConfig;
}

FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
InstantiationException, IllegalAccessException {
Class<?> formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gherkin.GherkinUtilsFormatterFunc");
Constructor<?> constructor = formatterFunc.getConstructor(GherkinUtilsConfig.class);
Class<?> formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gherkin.GherkinFormatterFormatterFunc");
Constructor<?> constructor = formatterFunc.getConstructor(GherkinFormatterConfig.class);
return (FormatterFunc) constructor.newInstance(gherkinSimpleConfig);
}
}
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
- Fix `Cannot set the value of task ... property 'taskService'` when Spotless is applied to sibling projects but not to their parent, a regression since `8.3.0`. Applying it to the root project with `apply false` is no longer necessary. ([#2877](https://github.com/diffplug/spotless/issues/2877))
### Changes
- README: example for formatting Dockerfiles with prettier and `prettier-plugin-sh`. ([#3158](https://github.com/diffplug/spotless/issues/3158))
- Replace `gherkinUtils` with `gherkinFormatter`. ([#3217](https://github.com/diffplug/spotless/issues/3217))

## [8.12.0] - 2026-11-21
### Added
Expand Down
12 changes: 6 additions & 6 deletions plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1518,23 +1518,23 @@ spotless {
spotless {
gherkin {
target 'src/**/*.feature' // you have to set the target manually
gherkinUtils() // has its own section below
gherkinFormatter() // has its own section below
}
}
```

### gherkinUtils
### gherkinFormatter

[homepage](https://github.com/cucumber/gherkin-utils). [changelog](https://github.com/cucumber/gherkin-utils/blob/main/CHANGELOG.md).
[homepage](https://github.com/cucumber/gherkin-formatter). [changelog](https://github.com/cucumber/gherkin-formatter/blob/main/CHANGELOG.md).

Uses a Gherkin pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects:
Uses a Gherkin document formatter that optionally allows configuring the number of spaces that are used to pretty print objects:

```gradle
spotless {
gherkin {
target 'src/**/*.feature' // required to be set explicitly
gherkinUtils()
.version('9.0.0') // optional: custom version of 'io.cucumber:gherkin-utils'
gherkinFormatter()
.version('0.1.0') // optional: custom version of 'io.cucumber:gherkin-formatter'
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@
import javax.inject.Inject;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.gherkin.GherkinUtilsStep;
import com.diffplug.spotless.gherkin.GherkinFormatterStep;

public class GherkinExtension extends FormatExtension {
static final String NAME = "gherkin";
Expand All @@ -36,17 +36,17 @@ protected void setupTask(SpotlessTask task) {
super.setupTask(task);
}

public GherkinUtilsConfig gherkinUtils() {
return new GherkinUtilsConfig();
public GherkinFormatterConfig gherkinFormatter() {
return new GherkinFormatterConfig();
}

public class GherkinUtilsConfig {
public class GherkinFormatterConfig {
private String version;
private int indent;

public GherkinUtilsConfig() {
this.version = GherkinUtilsStep.defaultVersion();
this.indent = com.diffplug.spotless.gherkin.GherkinUtilsConfig.defaultIndentSpaces();
public GherkinFormatterConfig() {
this.version = GherkinFormatterStep.defaultVersion();
this.indent = com.diffplug.spotless.gherkin.GherkinFormatterConfig.defaultIndentSpaces();
addStep(createStep());
}

Expand All @@ -56,7 +56,7 @@ public void version(String version) {
}

private FormatterStep createStep() {
return GherkinUtilsStep.create(new com.diffplug.spotless.gherkin.GherkinUtilsConfig(indent), version, provisioner());
return GherkinFormatterStep.create(new com.diffplug.spotless.gherkin.GherkinFormatterConfig(indent), version, provisioner());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 DiffPlug
* Copyright 2021-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@ public void defaultFormatting() throws IOException {
"spotless {",
" gherkin {",
" target 'examples/**/*.feature'",
" gherkinUtils()",
" gherkinFormatter()",
" }",
"}");
setFile("src/main/resources/example.feature").toResource("gherkin/minimalBefore.feature");
Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
- Fix npm/node executable discovery treating a directory (e.g. an `npm` folder inside `NODE_PATH`) as an executable. ([#3190](https://github.com/diffplug/spotless/issues/3190))
### Changes
- README: example for formatting Dockerfiles with prettier and `prettier-plugin-sh`. ([#3158](https://github.com/diffplug/spotless/issues/3158))
- Replace `gherkinUtils` with `gherkinFormatter`. ([#3217](https://github.com/diffplug/spotless/issues/3217))

## [3.12.0] - 2026-11-21
### Changes
Expand Down
14 changes: 7 additions & 7 deletions plugin-maven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1434,21 +1434,21 @@ When formatting shell scripts via `shfmt`, configure `shfmt` settings via `.edit
<include>src/**/*.feature</include>
</includes>

<gherkinUtils /> <!-- has its own section below -->
<gherkinFormatter /> <!-- has its own section below -->
</gherkin>
</configuration>
```

### gherkinUtils
### gherkinFormatter

[homepage](https://github.com/cucumber/gherkin-utils). [changelog](https://github.com/cucumber/gherkin-utils/blob/main/CHANGELOG.md).
[homepage](https://github.com/cucumber/gherkin-formatter). [changelog](https://github.com/cucumber/gherkin-formatter/blob/main/CHANGELOG.md).

Uses a Gherkin pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects:
Uses a Gherkin document formatter that optionally allows configuring the number of spaces that are used to pretty print documents:

```xml
<gherkinUtils>
<version>9.0.0</version> <!-- optional: Custom version of 'io.cucumber:gherkin-utils' -->
</gherkinUtils>
<gherkinFormatter>
<version>0.1.0</version> <!-- optional: Custom version of 'io.cucumber:gherkin-formatter' -->
</gherkinFormatter>
```

## Go
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 DiffPlug
* Copyright 2023-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,8 +36,8 @@ public String licenseHeaderDelimiter() {
return null;
}

public void addGherkinUtils(GherkinUtils gherkinUtils) {
addStepFactory(gherkinUtils);
public void addGherkinFormatter(GherkinFormatter gherkinFormatter) {
addStepFactory(gherkinFormatter);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 DiffPlug
* Copyright 2023-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,25 +18,24 @@
import org.apache.maven.plugins.annotations.Parameter;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.gherkin.GherkinUtilsConfig;
import com.diffplug.spotless.gherkin.GherkinUtilsStep;
import com.diffplug.spotless.gherkin.GherkinFormatterStep;
import com.diffplug.spotless.maven.FormatterFactory;
import com.diffplug.spotless.maven.FormatterStepConfig;
import com.diffplug.spotless.maven.FormatterStepFactory;

/**
* A {@link FormatterFactory} implementation that corresponds to {@code <gherkin><gherkinUtils>...</gherkinUtils></gherkin>} configuration element.
* A {@link FormatterFactory} implementation that corresponds to {@code <gherkin><gherkinFormatter>...</gherkinFormatter></gherkin>} configuration element.
*/
public class GherkinUtils implements FormatterStepFactory {
public class GherkinFormatter implements FormatterStepFactory {

@Parameter
private String version = GherkinUtilsStep.defaultVersion();
private String version = GherkinFormatterStep.defaultVersion();

@Parameter
private int indentWithSpaces = GherkinUtilsConfig.defaultIndentSpaces();
private int indentWithSpaces = com.diffplug.spotless.gherkin.GherkinFormatterConfig.defaultIndentSpaces();

@Override
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
return GherkinUtilsStep.create(new GherkinUtilsConfig(indentWithSpaces), version, stepConfig.getProvisioner());
return GherkinFormatterStep.create(new com.diffplug.spotless.gherkin.GherkinFormatterConfig(indentWithSpaces), version, stepConfig.getProvisioner());
}
}
Loading