Skip to content

Commit fa0b90d

Browse files
committed
feat: add tableTest format type for .table files
1 parent b09da49 commit fa0b90d

File tree

15 files changed

+268
-2
lines changed

15 files changed

+268
-2
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ 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.
1315
### Changes
1416
- Bump default `tabletest-formatter` version `1.0.1` -> `1.1.1`, now works with Java 17+.
1517

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: 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 `3.27.0`).
44

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

plugin-gradle/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

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+
- Add `tableTest` format type for standalone `.table` files.
68
### Changes
79
- Bump default `tabletest-formatter` version `1.0.1` -> `1.1.1`, now works with Java 17+.
810

plugin-maven/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,25 @@ When formatting shell scripts via `shfmt`, configure `shfmt` settings via `.edit
11901190
</shfmt>
11911191
```
11921192

1193+
## TableTest
1194+
1195+
[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).
1196+
1197+
```xml
1198+
<configuration>
1199+
<tableTest>
1200+
<includes>
1201+
<include>src/**/*.table</include>
1202+
</includes>
1203+
<tableTestFormatter>
1204+
<version>1.1.1</version> <!-- optional -->
1205+
</tableTestFormatter>
1206+
</tableTest>
1207+
</configuration>
1208+
```
1209+
1210+
[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.
1211+
11931212
## Gherkin
11941213

11951214
- `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)

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
@@ -82,6 +82,7 @@
8282
import com.diffplug.spotless.maven.scala.Scala;
8383
import com.diffplug.spotless.maven.shell.Shell;
8484
import com.diffplug.spotless.maven.sql.Sql;
85+
import com.diffplug.spotless.maven.tabletest.TableTest;
8586
import com.diffplug.spotless.maven.typescript.Typescript;
8687
import com.diffplug.spotless.maven.yaml.Yaml;
8788

@@ -208,6 +209,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
208209
@Parameter
209210
private Protobuf protobuf;
210211

212+
@Parameter
213+
private TableTest tableTest;
214+
211215
@Parameter(property = "spotlessFiles")
212216
private String filePatterns;
213217

@@ -410,7 +414,7 @@ private FileLocator getFileLocator() {
410414
}
411415

412416
private List<FormatterFactory> getFormatterFactories() {
413-
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))
417+
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))
414418
.filter(Objects::nonNull)
415419
.map(factory -> factory.init(repositorySystemSession))
416420
.collect(toList());

0 commit comments

Comments
 (0)