Skip to content

Commit df48b4d

Browse files
authored
Switch out Spotless for Immaculate, an alternative formatting plugin (#1530)
1 parent 304415b commit df48b4d

File tree

6 files changed

+24
-26
lines changed

6 files changed

+24
-26
lines changed

build.gradle

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import java.util.regex.Pattern
33

44
plugins {
55
id 'net.neoforged.gradleutils' version '3.0.0'
6-
id 'com.diffplug.spotless' version '6.22.0' apply false
6+
id 'dev.lukebemish.immaculate' version '0.1.6' apply false
77
id 'net.neoforged.licenser' version '0.7.5'
88
id 'neoforge.formatting-conventions'
99
id 'neoforge.versioning'
@@ -56,14 +56,14 @@ license {
5656
}
5757

5858
// Put spotless here because it wants the files to live inside the project root
59-
spotless {
60-
java {
61-
target rootProject.fileTree("src", {
59+
immaculate {
60+
workflows.named("java") {
61+
files.from rootProject.fileTree("src", {
6262
include "**/*.java"
6363
})
6464
}
65-
format 'patches', {
66-
target rootProject.fileTree("patches")
65+
workflows.register("patches") {
66+
files.from(rootProject.fileTree("patches"))
6767

6868
custom 'noImportChanges', { String fileContents ->
6969
if (fileContents.contains('+import') || fileContents.contains('-import')) {
@@ -152,7 +152,5 @@ spotless {
152152
custom 'jetbrainsNullablePatches', { String fileContents ->
153153
fileContents.replace('@javax.annotation.Nullable', '@org.jetbrains.annotations.Nullable')
154154
}
155-
156-
bumpThisNumberIfACustomStepChanges(5)
157155
}
158156
}

buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import java.util.regex.Matcher
22

3-
project.plugins.apply('com.diffplug.spotless')
3+
project.plugins.apply('dev.lukebemish.immaculate')
44

55
abstract class GeneratePackageInfos extends DefaultTask {
66
@InputFiles
@@ -36,15 +36,19 @@ final generatePackageInfos = tasks.register('generatePackageInfos', GeneratePack
3636
it.files.from fileTree("src/main/java")
3737
}
3838

39-
spotless {
40-
java {
41-
endWithNewline()
42-
indentWithSpaces()
43-
removeUnusedImports()
44-
toggleOffOn()
45-
// Pin version to 4.31 because of a Spotless bug https://github.com/diffplug/spotless/issues/1992
46-
eclipse('4.31').configFile rootProject.file('codeformat/formatter-config.xml')
47-
importOrder()
39+
immaculate {
40+
workflows.register('java') {
41+
java()
42+
trailingNewline()
43+
noTabs()
44+
googleFixImports()
45+
toggleOff = 'spotless:off'
46+
toggleOn = 'spotless:on'
47+
eclipse {
48+
version '3.37.0'
49+
config = rootProject.file('codeformat/formatter-config.xml')
50+
}
51+
4852

4953
// courtesy of diffplug/spotless#240
5054
// https://github.com/diffplug/spotless/issues/240#issuecomment-385206606
@@ -63,28 +67,27 @@ spotless {
6367
custom 'jetbrainsNullable', { String fileContents ->
6468
fileContents.replace('javax.annotation.Nullable', 'org.jetbrains.annotations.Nullable')
6569
}
66-
bumpThisNumberIfACustomStepChanges(3)
6770
}
6871
}
6972

7073
tasks.named('licenseFormat').configure {
7174
mustRunAfter generatePackageInfos
7275
}
73-
tasks.named('spotlessApply').configure {
76+
tasks.named('immaculateApply').configure {
7477
mustRunAfter generatePackageInfos
7578
mustRunAfter tasks.named('licenseFormat')
7679
}
7780

7881
tasks.register('applyAllFormatting', Task) {
7982
dependsOn generatePackageInfos
8083
dependsOn tasks.named('licenseFormat')
81-
dependsOn tasks.named('spotlessApply')
84+
dependsOn tasks.named('immaculateApply')
8285
group = 'verification'
8386
}
8487

8588
tasks.register('checkFormatting', Task) {
8689
dependsOn 'licenseCheck'
87-
dependsOn 'spotlessCheck'
90+
dependsOn 'immaculateCheck'
8891
group = 'verification'
8992
}
9093

coremods/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
plugins {
22
id 'java-library'
3-
id 'com.diffplug.spotless'
43
id 'net.neoforged.licenser'
54
id 'neoforge.formatting-conventions'
65
}

docs/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Contributing to NeoForge
2727
- If possible, write an automated test under the tests project. See [NEOGAMETESTS.md](NEOGAMETESTS.md) for more info.
2828
10. Run `gradlew genPatches` to generate patch-files from the patched sources
2929
11. Run `gradlew applyAllFormatting` to automatically format sources
30-
12. Check correct formatting with `gradlew spotlessCheck`
30+
12. Check correct formatting with `gradlew checkFormatting`
3131
13. Commit & Push
3232
14. Make PR
3333

testframework/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
plugins {
22
id 'java'
33
id 'maven-publish'
4-
id 'com.diffplug.spotless'
54
id 'net.neoforged.licenser'
65
id 'neoforge.formatting-conventions'
76
}

tests/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
plugins {
22
id 'java'
3-
id 'com.diffplug.spotless'
43
id 'net.neoforged.licenser'
54
id 'neoforge.formatting-conventions'
65
}

0 commit comments

Comments
 (0)