Skip to content

Commit

Permalink
Switch out Spotless for Immaculate, an alternative formatting plugin (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish authored Dec 13, 2024
1 parent 304415b commit df48b4d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
14 changes: 6 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.util.regex.Pattern

plugins {
id 'net.neoforged.gradleutils' version '3.0.0'
id 'com.diffplug.spotless' version '6.22.0' apply false
id 'dev.lukebemish.immaculate' version '0.1.6' apply false
id 'net.neoforged.licenser' version '0.7.5'
id 'neoforge.formatting-conventions'
id 'neoforge.versioning'
Expand Down Expand Up @@ -56,14 +56,14 @@ license {
}

// Put spotless here because it wants the files to live inside the project root
spotless {
java {
target rootProject.fileTree("src", {
immaculate {
workflows.named("java") {
files.from rootProject.fileTree("src", {
include "**/*.java"
})
}
format 'patches', {
target rootProject.fileTree("patches")
workflows.register("patches") {
files.from(rootProject.fileTree("patches"))

custom 'noImportChanges', { String fileContents ->
if (fileContents.contains('+import') || fileContents.contains('-import')) {
Expand Down Expand Up @@ -152,7 +152,5 @@ spotless {
custom 'jetbrainsNullablePatches', { String fileContents ->
fileContents.replace('@javax.annotation.Nullable', '@org.jetbrains.annotations.Nullable')
}

bumpThisNumberIfACustomStepChanges(5)
}
}
31 changes: 17 additions & 14 deletions buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.util.regex.Matcher

project.plugins.apply('com.diffplug.spotless')
project.plugins.apply('dev.lukebemish.immaculate')

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

spotless {
java {
endWithNewline()
indentWithSpaces()
removeUnusedImports()
toggleOffOn()
// Pin version to 4.31 because of a Spotless bug https://github.com/diffplug/spotless/issues/1992
eclipse('4.31').configFile rootProject.file('codeformat/formatter-config.xml')
importOrder()
immaculate {
workflows.register('java') {
java()
trailingNewline()
noTabs()
googleFixImports()
toggleOff = 'spotless:off'
toggleOn = 'spotless:on'
eclipse {
version '3.37.0'
config = rootProject.file('codeformat/formatter-config.xml')
}


// courtesy of diffplug/spotless#240
// https://github.com/diffplug/spotless/issues/240#issuecomment-385206606
Expand All @@ -63,28 +67,27 @@ spotless {
custom 'jetbrainsNullable', { String fileContents ->
fileContents.replace('javax.annotation.Nullable', 'org.jetbrains.annotations.Nullable')
}
bumpThisNumberIfACustomStepChanges(3)
}
}

tasks.named('licenseFormat').configure {
mustRunAfter generatePackageInfos
}
tasks.named('spotlessApply').configure {
tasks.named('immaculateApply').configure {
mustRunAfter generatePackageInfos
mustRunAfter tasks.named('licenseFormat')
}

tasks.register('applyAllFormatting', Task) {
dependsOn generatePackageInfos
dependsOn tasks.named('licenseFormat')
dependsOn tasks.named('spotlessApply')
dependsOn tasks.named('immaculateApply')
group = 'verification'
}

tasks.register('checkFormatting', Task) {
dependsOn 'licenseCheck'
dependsOn 'spotlessCheck'
dependsOn 'immaculateCheck'
group = 'verification'
}

Expand Down
1 change: 0 additions & 1 deletion coremods/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id 'java-library'
id 'com.diffplug.spotless'
id 'net.neoforged.licenser'
id 'neoforge.formatting-conventions'
}
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Contributing to NeoForge
- If possible, write an automated test under the tests project. See [NEOGAMETESTS.md](NEOGAMETESTS.md) for more info.
10. Run `gradlew genPatches` to generate patch-files from the patched sources
11. Run `gradlew applyAllFormatting` to automatically format sources
12. Check correct formatting with `gradlew spotlessCheck`
12. Check correct formatting with `gradlew checkFormatting`
13. Commit & Push
14. Make PR

Expand Down
1 change: 0 additions & 1 deletion testframework/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'java'
id 'maven-publish'
id 'com.diffplug.spotless'
id 'net.neoforged.licenser'
id 'neoforge.formatting-conventions'
}
Expand Down
1 change: 0 additions & 1 deletion tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id 'java'
id 'com.diffplug.spotless'
id 'net.neoforged.licenser'
id 'neoforge.formatting-conventions'
}
Expand Down

0 comments on commit df48b4d

Please sign in to comment.