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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ This document is intended for Spotless developers.
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Added
- Add `tableTest` format type for standalone `.table` files.
### Changes
- Bump default `tabletest-formatter` version `1.0.1` -> `1.1.0`, now works with Java 17+.

## [4.4.0] - 2026-03-02
### Added
Expand Down
11 changes: 3 additions & 8 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ def NEEDS_GLUE = [
'palantirJavaFormat',
'scalafmt',
'sortPom',
'tableTestFormatter',
'zjsonPatch',
]
// tableTestFormatter requires Java 21+
if (JavaVersion.current() >= JavaVersion.VERSION_21) {
NEEDS_GLUE << 'tableTestFormatter'
}

for (glue in NEEDS_GLUE) {
sourceSets.register(glue) {
Expand Down Expand Up @@ -127,10 +124,8 @@ dependencies {
// sortPom
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:4.0.0'
sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.17'
// tableTestFormatter (Java 21+ only)
if (JavaVersion.current() >= JavaVersion.VERSION_21) {
tableTestFormatterCompileOnly 'org.tabletest:tabletest-formatter-core:1.0.1'
}
// tableTestFormatter
tableTestFormatterCompileOnly 'org.tabletest:tabletest-formatter-core:1.1.0'
// zjsonPatch
zjsonPatchCompileOnly 'com.flipkart.zjsonpatch:zjsonpatch:0.4.16'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class TableTestFormatterStep implements Serializable {
private static final long serialVersionUID = 1L;
private static final String NAME = "tableTestFormatter";
private static final String MAVEN_COORDINATE = "org.tabletest:tabletest-formatter-core:";
private static final String DEFAULT_VERSION = "1.0.1";
private static final String DEFAULT_VERSION = "1.1.0";

private final JarState.Promised jarState;
private final String version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
import org.tabletest.formatter.config.Config;
import org.tabletest.formatter.config.EditorConfigProvider;
import org.tabletest.formatter.core.SourceFileFormatter;
import org.tabletest.formatter.core.TableTestFormatter;

import com.diffplug.spotless.FormatterFunc;

/**
* Formats {@code @TableTest} annotation tables in Java and Kotlin source files.
* Formats {@code @TableTest} annotation tables in Java, Kotlin, and standalone {@code .table} files.
*/
public class TableTestFormatterFunc implements FormatterFunc.NeedsFile {

private static final EditorConfigProvider CONFIG_PROVIDER = new EditorConfigProvider();

private final SourceFileFormatter sourceFormatter = new SourceFileFormatter();
private final TableTestFormatter tableFormatter = new TableTestFormatter();

@Override
public String applyWithFile(String unix, File file) throws Exception {
Expand All @@ -42,6 +44,11 @@ public String applyWithFile(String unix, File file) throws Exception {
return formatted.equals(unix) ? unix : formatted;
}

if (fileName.endsWith(".table")) {
String formatted = tableFormatter.format(unix, "", Config.NO_INDENT);
return formatted.equals(unix) ? unix : formatted;
}

return unix;
}
}
4 changes: 4 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

## [Unreleased]
### Added
- Add `tableTest` format type for standalone `.table` files.
### Changes
- Bump default `tabletest-formatter` version `1.0.1` -> `1.1.0`, now works with Java 17+.

## [8.3.0] - 2026-03-02
### Added
Expand Down
32 changes: 30 additions & 2 deletions plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ spotless {
java {
tableTestFormatter()
// optional: you can specify a specific version
tableTestFormatter('1.0.1')
tableTestFormatter('1.1.0')
```

<a name="applying-to-groovy-source"></a>
Expand Down Expand Up @@ -616,7 +616,7 @@ spotless {
kotlin {
tableTestFormatter()
// optional: you can specify a specific version
tableTestFormatter('1.0.1')
tableTestFormatter('1.1.0')
```

<a name="applying-scalafmt-to-scala-files"></a>
Expand Down Expand Up @@ -1265,6 +1265,34 @@ shfmt().pathToExe('/opt/homebrew/bin/shfmt')

<a name="applying-freshmark-to-markdown-files"></a>

## TableTest

- `com.diffplug.gradle.spotless.TableTestExtension` [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TableTestExtension.java)

```gradle
spotless {
tableTest {
target 'src/**/*.table' // you have to set the target manually
tableTestFormatter() // has its own section below
}
}
```

### tabletest-formatter

[homepage](https://github.com/nchaugen/tabletest-formatter). [changelog](https://github.com/nchaugen/tabletest-formatter/releases). Formats standalone [TableTest](https://github.com/nchaugen/tabletest) `.table` files.

```gradle
spotless {
tableTest {
target 'src/**/*.table'
tableTestFormatter()
// optional: you can specify a specific version
tableTestFormatter('1.1.0')
}
}
```

## Gherkin

- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/8.3.0/com/diffplug/gradle/spotless/GherkinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ public void javascript(Action<JavascriptExtension> closure) {
format(JavascriptExtension.NAME, JavascriptExtension.class, closure);
}

/** Configures the special tableTest-specific extension for .table files. */
public void tableTest(Action<TableTestExtension> closure) {
requireNonNull(closure);
format(TableTestExtension.NAME, TableTestExtension.class, closure);
}

/** Configures the special typescript-specific extension for typescript files. */
public void typescript(Action<TypescriptExtension> closure) {
format(TypescriptExtension.NAME, TypescriptExtension.class, closure);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.gradle.spotless;

import javax.inject.Inject;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.java.TableTestFormatterStep;

public class TableTestExtension extends FormatExtension {
static final String NAME = "tableTest";

@Inject
public TableTestExtension(SpotlessExtension spotless) {
super(spotless);
}

@Override
protected void setupTask(SpotlessTask task) {
if (target == null) {
throw noDefaultTargetException();
}
super.setupTask(task);
}

public TableTestFormatterConfig tableTestFormatter() {
return tableTestFormatter(TableTestFormatterStep.defaultVersion());
}

public TableTestFormatterConfig tableTestFormatter(String version) {
return new TableTestFormatterConfig(version);
}

public class TableTestFormatterConfig {
private final String version;

TableTestFormatterConfig(String version) {
this.version = version;
addStep(createStep());
}

private FormatterStep createStep() {
return TableTestFormatterStep.create(version, provisioner());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.gradle.spotless;

import java.io.IOException;

import org.junit.jupiter.api.Test;

public class TableTestExtensionTest extends GradleIntegrationHarness {
@Test
public void defaultFormatting() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'java'",
" id 'com.diffplug.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless {",
" tableTest {",
" target 'src/**/*.table'",
" tableTestFormatter()",
" }",
"}");
setFile("src/main/resources/example.table").toResource("tableTest/tableFileUnformatted.test");
setFile("other/example.table").toResource("tableTest/tableFileUnformatted.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/resources/example.table").sameAsResource("tableTest/tableFileFormatted.test");
assertFile("other/example.table").sameAsResource("tableTest/tableFileUnformatted.test");
}
}
4 changes: 4 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Added
- Add `tableTest` format type for standalone `.table` files.
### Changes
- Bump default `tabletest-formatter` version `1.0.1` -> `1.1.0`, now works with Java 17+.

## [3.3.0] - 2026-03-02
### Added
Expand Down
23 changes: 21 additions & 2 deletions plugin-maven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ These mechanisms already exist for the Gradle plugin.

```xml
<tableTestFormatter>
<version>1.0.1</version> <!-- optional -->
<version>1.1.0</version> <!-- optional -->
</tableTestFormatter>
```

Expand Down Expand Up @@ -543,7 +543,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `.

```xml
<tableTestFormatter>
<version>1.0.1</version> <!-- optional -->
<version>1.1.0</version> <!-- optional -->
</tableTestFormatter>
```

Expand Down Expand Up @@ -1190,6 +1190,25 @@ When formatting shell scripts via `shfmt`, configure `shfmt` settings via `.edit
</shfmt>
```

## TableTest

[code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/tabletest/TableTest.java). [available steps](https://github.com/diffplug/spotless/tree/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/tabletest).

```xml
<configuration>
<tableTest>
<includes>
<include>src/**/*.table</include>
</includes>
<tableTestFormatter>
<version>1.1.0</version> <!-- optional -->
</tableTestFormatter>
</tableTest>
</configuration>
```

[homepage](https://github.com/nchaugen/tabletest-formatter). [changelog](https://github.com/nchaugen/tabletest-formatter/releases). Formats standalone [TableTest](https://github.com/nchaugen/tabletest) `.table` files.

## 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import com.diffplug.spotless.maven.scala.Scala;
import com.diffplug.spotless.maven.shell.Shell;
import com.diffplug.spotless.maven.sql.Sql;
import com.diffplug.spotless.maven.tabletest.TableTest;
import com.diffplug.spotless.maven.typescript.Typescript;
import com.diffplug.spotless.maven.yaml.Yaml;

Expand Down Expand Up @@ -208,6 +209,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
@Parameter
private Protobuf protobuf;

@Parameter
private TableTest tableTest;

@Parameter(property = "spotlessFiles")
private String filePatterns;

Expand Down Expand Up @@ -410,7 +414,7 @@ private FileLocator getFileLocator() {
}

private List<FormatterFactory> getFormatterFactories() {
return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, css, typescript, javascript, antlr4, pom, sql, python, markdown, json, shell, yaml, gherkin, go, rdf, protobuf))
return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, css, typescript, javascript, antlr4, pom, sql, python, markdown, json, shell, yaml, gherkin, go, rdf, protobuf, tableTest))
.filter(Objects::nonNull)
.map(factory -> factory.init(repositorySystemSession))
.collect(toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.maven.tabletest;

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

import org.apache.maven.project.MavenProject;

import com.diffplug.spotless.maven.FormatterFactory;

/**
* A {@link FormatterFactory} implementation that corresponds to {@code <tableTest>...</tableTest>} configuration element.
*/
public class TableTest extends FormatterFactory {
@Override
public Set<String> defaultIncludes(MavenProject project) {
return Collections.emptySet();
}

@Override
public String licenseHeaderDelimiter() {
return null;
}

public void addTableTestFormatter(TableTestFormatter tableTestFormatter) {
addStepFactory(tableTestFormatter);
}
}
Loading
Loading