From 2016e39deaa80ba02ebebb4398ce45928f650a45 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 23 Jun 2022 20:53:03 +0100 Subject: [PATCH] Spotless autoformatter (#32) * Fix editorconfig for language files * Add spotless autoformatting plugin * Autoformatting fixes * Update build.gradle timestamp --- .editorconfig | 3 ++ build.gradle | 38 +++++++++++++++++-- .../java/com/myname/mymodid/ClientProxy.java | 4 +- .../java/com/myname/mymodid/CommonProxy.java | 30 ++++----------- src/main/java/com/myname/mymodid/Config.java | 10 ++--- src/main/java/com/myname/mymodid/MyMod.java | 4 +- src/main/java/com/myname/mymodid/Tags.java | 2 +- 7 files changed, 56 insertions(+), 35 deletions(-) diff --git a/.editorconfig b/.editorconfig index 6effbc9..4ffbd90 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,3 +17,6 @@ end_of_line = crlf [*.{dtd,json,info,mcmeta,md,sh,svg,xml,xsd,xsl,yaml,yml}] indent_size = 2 + +[*.lang] +trim_trailing_whitespace = false diff --git a/build.gradle b/build.gradle index 515d16d..94e9c84 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1655755555 +//version: 1656003794 /* DO NOT CHANGE THIS FILE! @@ -57,6 +57,7 @@ plugins { id 'com.palantir.git-version' version '0.13.0' apply false id 'de.undercouch.download' version '5.0.1' id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false + id "com.diffplug.spotless" version "6.7.2" } if (project.file('.git/HEAD').isFile()) { @@ -83,6 +84,37 @@ idea { } } +// Spotless autoformatter +// See https://github.com/diffplug/spotless/tree/main/plugin-gradle +// Can be locally toggled via spotless:off/spotless:on comments +spotless { + encoding 'UTF-8' + + format 'misc', { + target '*.md', '.gitignore' + + trimTrailingWhitespace() + indentWithSpaces(4) + endWithNewline() + } + java { + toggleOffOn() + importOrder() + removeUnusedImports() + palantirJavaFormat('1.1.0') // last version supporting jvm 8 + } + kotlin { + toggleOffOn() + ktfmt('0.39') + } + groovyGradle { + toggleOffOn() + importOrder() + target '*.gradle' + greclipse('4.19.0') // last version supporting jvm 8 + } +} + if(JavaVersion.current() != JavaVersion.VERSION_1_8) { throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) } @@ -699,7 +731,7 @@ task deobfParams { println("Parsing params.csv ...") Map params = new HashMap<>() - Files.lines(Paths.get(paramsCSV)).forEach{line -> + Files.lines(Paths.get(paramsCSV)).forEach{line -> String[] cells = line.split(",") if(cells.length > 2 && cells[0].matches("p_i?\\d+_\\d+_")) { params.put(cells[0], cells[1]) @@ -824,7 +856,7 @@ def deobf(String sourceURL, String rawFileName) { String mappingsZIP = "$cacheDir/forge_gradle/maven_downloader/de/oceanlabs/mcp/mcp_snapshot_nodoc/$id/mcp_snapshot_nodoc-${id}.zip" zipMappings(mappingsZIP, remoteMappings, bon2Dir) - + mappingsVer = "snapshot_$id" } else { mappingsVer = "${channel}_$mappingsVersion" diff --git a/src/main/java/com/myname/mymodid/ClientProxy.java b/src/main/java/com/myname/mymodid/ClientProxy.java index 5c5252b..9245fc1 100644 --- a/src/main/java/com/myname/mymodid/ClientProxy.java +++ b/src/main/java/com/myname/mymodid/ClientProxy.java @@ -6,7 +6,7 @@ public class ClientProxy extends CommonProxy { // preInit "Run before anything else. Read your config, create blocks, items, // etc, and register them with the GameRegistry." - public void preInit(FMLPreInitializationEvent event) { + public void preInit(FMLPreInitializationEvent event) { super.preInit(event); } @@ -40,4 +40,4 @@ public class ClientProxy extends CommonProxy { public void serverStopped(FMLServerStoppedEvent event) { super.serverStopped(event); } -} \ No newline at end of file +} diff --git a/src/main/java/com/myname/mymodid/CommonProxy.java b/src/main/java/com/myname/mymodid/CommonProxy.java index bcc5921..78adfa3 100644 --- a/src/main/java/com/myname/mymodid/CommonProxy.java +++ b/src/main/java/com/myname/mymodid/CommonProxy.java @@ -6,7 +6,7 @@ public class CommonProxy { // preInit "Run before anything else. Read your config, create blocks, items, // etc, and register them with the GameRegistry." - public void preInit(FMLPreInitializationEvent event) { + public void preInit(FMLPreInitializationEvent event) { Config.syncronizeConfiguration(event.getSuggestedConfigurationFile()); MyMod.info(Config.greeting); @@ -14,33 +14,19 @@ public class CommonProxy { } // load "Do your mod setup. Build whatever data structures you care about. Register recipes." - public void init(FMLInitializationEvent event) { - - } + public void init(FMLInitializationEvent event) {} // postInit "Handle interaction with other mods, complete your setup based on this." - public void postInit(FMLPostInitializationEvent event) { + public void postInit(FMLPostInitializationEvent event) {} - } - - public void serverAboutToStart(FMLServerAboutToStartEvent event) { - - } + public void serverAboutToStart(FMLServerAboutToStartEvent event) {} // register server commands in this event handler - public void serverStarting(FMLServerStartingEvent event) { + public void serverStarting(FMLServerStartingEvent event) {} - } + public void serverStarted(FMLServerStartedEvent event) {} - public void serverStarted(FMLServerStartedEvent event) { + public void serverStopping(FMLServerStoppingEvent event) {} - } - - public void serverStopping(FMLServerStoppingEvent event) { - - } - - public void serverStopped(FMLServerStoppedEvent event) { - - } + public void serverStopped(FMLServerStoppedEvent event) {} } diff --git a/src/main/java/com/myname/mymodid/Config.java b/src/main/java/com/myname/mymodid/Config.java index 33136b9..7f75f86 100644 --- a/src/main/java/com/myname/mymodid/Config.java +++ b/src/main/java/com/myname/mymodid/Config.java @@ -1,10 +1,9 @@ package com.myname.mymodid; +import java.io.File; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; -import java.io.File; - public class Config { private static class Defaults { @@ -21,11 +20,12 @@ public class Config { Configuration configuration = new Configuration(configFile); configuration.load(); - Property greetingProperty = configuration.get(Categories.general, "greeting", Defaults.greeting, "How shall I greet?"); + Property greetingProperty = + configuration.get(Categories.general, "greeting", Defaults.greeting, "How shall I greet?"); greeting = greetingProperty.getString(); - if(configuration.hasChanged()) { + if (configuration.hasChanged()) { configuration.save(); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/myname/mymodid/MyMod.java b/src/main/java/com/myname/mymodid/MyMod.java index 9f9618c..499280d 100644 --- a/src/main/java/com/myname/mymodid/MyMod.java +++ b/src/main/java/com/myname/mymodid/MyMod.java @@ -11,7 +11,7 @@ public class MyMod { private static Logger LOG = LogManager.getLogger(Tags.MODID); - @SidedProxy(clientSide= Tags.GROUPNAME + ".ClientProxy", serverSide=Tags.GROUPNAME + ".CommonProxy") + @SidedProxy(clientSide = Tags.GROUPNAME + ".ClientProxy", serverSide = Tags.GROUPNAME + ".CommonProxy") public static CommonProxy proxy; @Mod.EventHandler @@ -74,4 +74,4 @@ public class MyMod { public static void error(String message) { LOG.error(message); } -} \ No newline at end of file +} diff --git a/src/main/java/com/myname/mymodid/Tags.java b/src/main/java/com/myname/mymodid/Tags.java index 568778f..58726ce 100644 --- a/src/main/java/com/myname/mymodid/Tags.java +++ b/src/main/java/com/myname/mymodid/Tags.java @@ -9,4 +9,4 @@ public class Tags { public static final String MODNAME = "GRADLETOKEN_MODNAME"; public static final String VERSION = "GRADLETOKEN_VERSION"; public static final String GROUPNAME = "GRADLETOKEN_GROUPNAME"; -} \ No newline at end of file +}