Skip to content

Commit 07fe63f

Browse files
authored
Add tableTest format type for .table files (#2880)
2 parents 8334155 + fa0b90d commit 07fe63f

File tree

18 files changed

+284
-22
lines changed

18 files changed

+284
-22
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ 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+
- Add `tableTest` format type for standalone `.table` files.
15+
### Changes
16+
- Bump default `tabletest-formatter` version `1.0.1` -> `1.1.1`, now works with Java 17+.
1317

1418
## [4.4.0] - 2026-03-02
1519
### Added

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ktfmt = "com.facebook:ktfmt:0.61"
5454
palantir-java-format = "com.palantir.javaformat:palantir-java-format:1.1.0"
5555
scalafmt-core = "org.scalameta:scalafmt-core_2.13:3.8.1"
5656
sortpom-sorter = "com.github.ekryd.sortpom:sortpom-sorter:4.0.0"
57-
tabletest-formatter-core = "org.tabletest:tabletest-formatter-core:1.0.1"
57+
tabletest-formatter-core = "org.tabletest:tabletest-formatter-core:1.1.1"
5858
zjsonpatch = "com.flipkart.zjsonpatch:zjsonpatch:0.4.16"
5959

6060
rewrite-recipe-migrate-java = "org.openrewrite.recipe:rewrite-migrate-java:3.28.0"

lib/build.gradle

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ def NEEDS_GLUE = [
2424
'palantirJavaFormat',
2525
'scalafmt',
2626
'sortPom',
27+
'tableTestFormatter',
2728
'zjsonPatch',
2829
]
29-
// tableTestFormatter requires Java 21+
30-
if (JavaVersion.current() >= JavaVersion.VERSION_21) {
31-
NEEDS_GLUE << 'tableTestFormatter'
32-
}
3330

3431
for (glue in NEEDS_GLUE) {
3532
sourceSets.register(glue) {
@@ -125,10 +122,8 @@ dependencies {
125122
// sortPom
126123
sortPomCompileOnly libs.sortpom.sorter
127124
sortPomCompileOnly libs.slf4j.api
128-
// tableTestFormatter (Java 21+ only)
129-
if (JavaVersion.current() >= JavaVersion.VERSION_21) {
130-
tableTestFormatterCompileOnly libs.tabletest.formatter.core
131-
}
125+
// tableTestFormatter
126+
tableTestFormatterCompileOnly libs.tabletest.formatter.core
132127
// zjsonPatch
133128
zjsonPatchCompileOnly libs.zjsonpatch
134129
}

lib/src/main/java/com/diffplug/spotless/java/TableTestFormatterStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class TableTestFormatterStep implements Serializable {
3434
private static final long serialVersionUID = 1L;
3535
private static final String NAME = "tableTestFormatter";
3636
private static final String MAVEN_COORDINATE = "org.tabletest:tabletest-formatter-core:";
37-
private static final String DEFAULT_VERSION = "1.0.1";
37+
private static final String DEFAULT_VERSION = "1.1.1";
3838

3939
private final JarState.Promised jarState;
4040
private final String version;

lib/src/tableTestFormatter/java/com/diffplug/spotless/glue/java/TableTestFormatterFunc.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@
2020
import org.tabletest.formatter.config.Config;
2121
import org.tabletest.formatter.config.EditorConfigProvider;
2222
import org.tabletest.formatter.core.SourceFileFormatter;
23+
import org.tabletest.formatter.core.TableTestFormatter;
2324

2425
import com.diffplug.spotless.FormatterFunc;
2526

2627
/**
27-
* Formats {@code @TableTest} annotation tables in Java and Kotlin source files.
28+
* Formats {@code @TableTest} annotation tables in Java, Kotlin, and standalone {@code .table} files.
2829
*/
2930
public class TableTestFormatterFunc implements FormatterFunc.NeedsFile {
3031

3132
private static final EditorConfigProvider CONFIG_PROVIDER = new EditorConfigProvider();
3233

3334
private final SourceFileFormatter sourceFormatter = new SourceFileFormatter();
35+
private final TableTestFormatter tableFormatter = new TableTestFormatter();
3436

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

47+
if (fileName.endsWith(".table")) {
48+
String formatted = tableFormatter.format(unix, "", Config.NO_INDENT);
49+
return formatted.equals(unix) ? unix : formatted;
50+
}
51+
4552
return unix;
4653
}
4754
}

plugin-gradle/CHANGES.md

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

55
## [Unreleased]
6+
### Added
7+
- Add `tableTest` format type for standalone `.table` files.
8+
### Changes
9+
- Bump default `tabletest-formatter` version `1.0.1` -> `1.1.1`, now works with Java 17+.
610

711
## [8.3.0] - 2026-03-02
812
### Added

plugin-gradle/README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ spotless {
439439
java {
440440
tableTestFormatter()
441441
// optional: you can specify a specific version
442-
tableTestFormatter('1.0.1')
442+
tableTestFormatter('1.1.1')
443443
```
444444

445445
<a name="applying-to-groovy-source"></a>
@@ -616,7 +616,7 @@ spotless {
616616
kotlin {
617617
tableTestFormatter()
618618
// optional: you can specify a specific version
619-
tableTestFormatter('1.0.1')
619+
tableTestFormatter('1.1.1')
620620
```
621621

622622
<a name="applying-scalafmt-to-scala-files"></a>
@@ -1265,6 +1265,34 @@ shfmt().pathToExe('/opt/homebrew/bin/shfmt')
12651265
12661266
<a name="applying-freshmark-to-markdown-files"></a>
12671267
1268+
## TableTest
1269+
1270+
- `com.diffplug.gradle.spotless.TableTestExtension` [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TableTestExtension.java)
1271+
1272+
```gradle
1273+
spotless {
1274+
tableTest {
1275+
target 'src/**/*.table' // you have to set the target manually
1276+
tableTestFormatter() // has its own section below
1277+
}
1278+
}
1279+
```
1280+
1281+
### tabletest-formatter
1282+
1283+
[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.
1284+
1285+
```gradle
1286+
spotless {
1287+
tableTest {
1288+
target 'src/**/*.table'
1289+
tableTestFormatter()
1290+
// optional: you can specify a specific version
1291+
tableTestFormatter('1.1.1')
1292+
}
1293+
}
1294+
```
1295+
12681296
## Gherkin
12691297
12701298
- `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)

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ public void javascript(Action<JavascriptExtension> closure) {
183183
format(JavascriptExtension.NAME, JavascriptExtension.class, closure);
184184
}
185185

186+
/** Configures the special tableTest-specific extension for .table files. */
187+
public void tableTest(Action<TableTestExtension> closure) {
188+
requireNonNull(closure);
189+
format(TableTestExtension.NAME, TableTestExtension.class, closure);
190+
}
191+
186192
/** Configures the special typescript-specific extension for typescript files. */
187193
public void typescript(Action<TypescriptExtension> closure) {
188194
format(TypescriptExtension.NAME, TypescriptExtension.class, closure);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2026 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.gradle.spotless;
17+
18+
import javax.inject.Inject;
19+
20+
import com.diffplug.spotless.FormatterStep;
21+
import com.diffplug.spotless.java.TableTestFormatterStep;
22+
23+
public class TableTestExtension extends FormatExtension {
24+
static final String NAME = "tableTest";
25+
26+
@Inject
27+
public TableTestExtension(SpotlessExtension spotless) {
28+
super(spotless);
29+
}
30+
31+
@Override
32+
protected void setupTask(SpotlessTask task) {
33+
if (target == null) {
34+
throw noDefaultTargetException();
35+
}
36+
super.setupTask(task);
37+
}
38+
39+
public TableTestFormatterConfig tableTestFormatter() {
40+
return tableTestFormatter(TableTestFormatterStep.defaultVersion());
41+
}
42+
43+
public TableTestFormatterConfig tableTestFormatter(String version) {
44+
return new TableTestFormatterConfig(version);
45+
}
46+
47+
public class TableTestFormatterConfig {
48+
private final String version;
49+
50+
TableTestFormatterConfig(String version) {
51+
this.version = version;
52+
addStep(createStep());
53+
}
54+
55+
private FormatterStep createStep() {
56+
return TableTestFormatterStep.create(version, provisioner());
57+
}
58+
}
59+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2026 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.gradle.spotless;
17+
18+
import java.io.IOException;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
public class TableTestExtensionTest extends GradleIntegrationHarness {
23+
@Test
24+
public void defaultFormatting() throws IOException {
25+
setFile("build.gradle").toLines(
26+
"plugins {",
27+
" id 'java'",
28+
" id 'com.diffplug.spotless'",
29+
"}",
30+
"repositories { mavenCentral() }",
31+
"spotless {",
32+
" tableTest {",
33+
" target 'src/**/*.table'",
34+
" tableTestFormatter()",
35+
" }",
36+
"}");
37+
setFile("src/main/resources/example.table").toResource("tableTest/tableFileUnformatted.test");
38+
setFile("other/example.table").toResource("tableTest/tableFileUnformatted.test");
39+
gradleRunner().withArguments("spotlessApply").build();
40+
assertFile("src/main/resources/example.table").sameAsResource("tableTest/tableFileFormatted.test");
41+
assertFile("other/example.table").sameAsResource("tableTest/tableFileUnformatted.test");
42+
}
43+
}

0 commit comments

Comments
 (0)