Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch out spotless for an alternative #1530

Open
wants to merge 16 commits into
base: 1.21.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1' 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()
sciwhiz12 marked this conversation as resolved.
Show resolved Hide resolved
toggleOff = 'spotless:off'
toggleOn = 'spotless:on'
eclipse {
version '3.37.0'
sciwhiz12 marked this conversation as resolved.
Show resolved Hide resolved
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)
sciwhiz12 marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
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