Skip to content

Commit e7eff3e

Browse files
committed
Use Spotless formatting
1 parent 1b527e9 commit e7eff3e

5 files changed

Lines changed: 42 additions & 31 deletions

File tree

.github/workflows/nix.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ jobs:
3131

3232
- run: nix flake check -L
3333

34+
format:
35+
runs-on: ubuntu-latest
36+
name: Formatting
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- uses: DeterminateSystems/nix-installer-action@v22
41+
with:
42+
summarize: false
43+
44+
- uses: DeterminateSystems/magic-nix-cache-action@v13
45+
46+
- run: gradle spotlessCheck --no-daemon
47+
3448
test:
3549
runs-on: ubuntu-latest
3650
name: Tests (JDK ${{ matrix.java }})

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ These are the main components of the project.
5858
| `gradle :scip-snapshots:saveSnapshots --no-daemon` | terminal | Regenerate Java and Kotlin snapshot goldens. |
5959
| `gradle :scip-java:installDist --no-daemon` | terminal | Build a local `scip-java` distribution under `scip-java/build/install/`. |
6060
| `gradle :scip-java:run --args='--cwd DIRECTORY'` | terminal | Run `scip-java` against a given Gradle/Maven build. |
61-
| `google-java-format --replace $(git ls-files '*.java')` | terminal | Format Java sources (from `nix develop`). Enforced by `nix flake check`. |
62-
| `ktfmt --kotlinlang-style $(git ls-files '*.kt')` | terminal | Format Kotlin sources (from `nix develop`). Enforced by `nix flake check`. |
61+
| `gradle format` | terminal | Format Java and Kotlin sources with Spotless. |
62+
| `gradle spotlessCheck` | terminal | Check Java and Kotlin formatting. Enforced by GitHub Actions. |
6363

6464
## Import the project into IntelliJ
6565

build.gradle.kts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
1+
plugins {
2+
alias(libs.plugins.spotless)
3+
}
4+
15
tasks.register("saveSnapshots") {
26
group = "verification"
37
description = "Regenerates all SCIP snapshot goldens."
48
dependsOn(":scip-snapshots:saveSnapshots")
59
}
10+
11+
spotless {
12+
java {
13+
target("scip-*/src/**/*.java")
14+
targetExclude("scip-java/src/test/resources/fixtures/**")
15+
googleJavaFormat("1.28.0")
16+
}
17+
18+
kotlin {
19+
target("build-logic/src/**/*.kt", "scip-*/src/**/*.kt")
20+
targetExclude("scip-java/src/test/resources/fixtures/**")
21+
ktfmt("0.61").kotlinlangStyle()
22+
}
23+
}
24+
25+
tasks.register("format") {
26+
group = "formatting"
27+
description = "Formats Java and Kotlin sources."
28+
dependsOn("spotlessApply")
29+
}

flake.nix

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
buildInputs = with pkgs; [
3030
bazelisk
3131
git
32-
google-java-format
3332
(gradle_9.override ({ java = jdk; }))
3433
jdk
3534
jq
36-
ktfmt
3735
(maven.override ({ jdk_headless = jdk; }))
3836
nixfmt
3937
nodejs
@@ -48,33 +46,6 @@
4846
${pkgs.actionlint}/bin/actionlint ${./.github/workflows}/*.yaml
4947
touch $out
5048
'';
51-
javafmt = pkgs.runCommand "check-javafmt" { } ''
52-
cd ${./.}
53-
# Exclude minimized fixtures and generated SCIP snapshot goldens
54-
# (coupled to exact line/column annotations), the standalone example
55-
# projects, and the scip-java build-tool test fixtures: these all mirror
56-
# real-world project layouts that must not be reformatted here.
57-
find . -name '*.java' \
58-
-not -path './examples/*' \
59-
-not -path './scip-snapshots/cases/*' \
60-
-not -path './scip-snapshots/expected/*' \
61-
-not -path './scip-java/src/test/resources/fixtures/*' \
62-
-exec ${pkgs.google-java-format}/bin/google-java-format --dry-run --set-exit-if-changed {} +
63-
touch $out
64-
'';
65-
ktfmt = pkgs.runCommand "check-ktfmt" { } ''
66-
cd ${./.}
67-
# Exclude minimized Kotlin snapshots (coupled to generated SCIP
68-
# goldens with exact line/column annotations) and the scip-java
69-
# build-tool test fixtures (real-world project layouts): neither may
70-
# be reformatted.
71-
find . -name '*.kt' \
72-
-not -path './scip-snapshots/cases/*' \
73-
-not -path './scip-snapshots/expected/*' \
74-
-not -path './scip-java/src/test/resources/fixtures/*' \
75-
-exec ${pkgs.ktfmt}/bin/ktfmt --kotlinlang-style --dry-run --set-exit-if-changed {} +
76-
touch $out
77-
'';
7849
nixfmt = pkgs.runCommand "check-nixfmt" { } ''
7950
${pkgs.nixfmt}/bin/nixfmt --check ${./flake.nix}
8051
touch $out

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ protobuf = "4.34.2"
1414
protobuf-plugin = "0.10.0"
1515
scip-bindings = "0.8.0"
1616
shadow = "9.4.3"
17+
spotless = "8.7.0"
1718
vanniktech-maven-publish = "0.35.0"
1819

1920
[libraries]
@@ -43,4 +44,5 @@ scip-kotlin-bindings = { module = "org.scip-code:scip-kotlin-bindings", version.
4344
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
4445
protobuf = { id = "com.google.protobuf", version.ref = "protobuf-plugin" }
4546
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
47+
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
4648
vanniktech-maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-maven-publish" }

0 commit comments

Comments
 (0)