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

Add Spotless and Checkstyle #1189

Open
wants to merge 10 commits into
base: master
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
30 changes: 29 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
plugins {
// Building
id 'fabric-loom' version '1.9-SNAPSHOT'
id "de.hysky.skyblocker.annotation-processor"
id "com.diffplug.spotless" version "6.20.0"
id "checkstyle"
// Publishing
id 'maven-publish'
id "me.modmuss50.mod-publish-plugin" version "0.8.1"
id "de.hysky.skyblocker.annotation-processor"
}

version = "${project.mod_version}+${project.minecraft_version}"
Expand Down Expand Up @@ -246,6 +250,30 @@ test {
useJUnitPlatform()
}

spotless {
java {
removeUnusedImports()
//indentWithTabs() // TODO: turn on when more files are converted to tabs
trimTrailingWhitespace()
}

json {
target 'src/**/lang/en_us.json'
targetExclude 'src/**/generated/**'
gson().indentWithSpaces(2)
}

groovyGradle {
target 'src/**/*.gradle', '*.gradle', 'gradle/*.gradle'
greclipse()
}
}

checkstyle {
toolVersion = "10.20.2"
configFile = rootProject.file("checkstyle.xml")
}

publishMods {
file = remapJar.archiveFile
changelog = System.getenv('CHANGELOG')
Expand Down
73 changes: 73 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="fileExtensions" value="java"/>
<property name="localeLanguage" value="en"/>
<property name="localeCountry" value="US"/>
<property name="tabWidth" value="4"/>

<module name="NewlineAtEndOfFile"/>

<!-- disallow trailing whitespace -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="trailing whitespace"/>
</module>

<module name="TreeWalker">
<!-- Allow "//CHECKSTYLE.OFF: <InspectionName>" and "//CHECKSTYLE.ON: <InspectionName>" pairs to toggle some inspections -->
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>

<!-- Ensure all imports are ship shape -->
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>

<module name="SeparatorWrap">
<property name="tokens" value="DOT,ELLIPSIS,AT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="tokens" value="COMMA,SEMI"/>
<property name="option" value="eol"/>
</module>

<module name="ParenPad"/>
<module name="NoWhitespaceBefore"/>
<module name="NoWhitespaceAfter">
<!-- allow ARRAY_INIT -->
<property name="tokens" value="AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP"/>
</module>
<module name="WhitespaceAfter"/>
<module name="GenericWhitespace"/>

<module name="ArrayTypeStyle"/>
<module name="DefaultComesLast">
<property name="skipIfLastAndSharedWithCase" value="true"/>
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>

<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<module name="AnnotationLocation"/>
<module name="MissingOverride"/>

<!-- Enforce tabs -->
<!-- TODO: enforce tabs in the future -->
<!--<module name="RegexpSinglelineJava">-->
<!--<property name="format" value="^\t* ([^*]|\*[^ /])"/>-->
<!--<property name="message" value="non-tab indentation"/>-->
<!--</module>-->

<module name="OuterTypeFilename"/>
<module name="PackageDeclaration"/>
</module>
</module>
16 changes: 8 additions & 8 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import net.minecraft.client.util.math.Rect2i;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.*;
import net.minecraft.recipe.book.CraftingRecipeCategory;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@JeiPlugin
public class SkyblockerJEIPlugin implements IModPlugin {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/hysky/skyblocker/config/ImageRepoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static String checkSavedCommitData() throws IOException {

/**
* Writes the {@code newHash} into a file to be used to check for repo updates.
*
*
* @implNote Checking whether the directory exists or not isn't needed as this is called after all files are written successfully.
*/
private static void writeCommitData(String newHash) throws IOException {
Expand All @@ -122,7 +122,7 @@ private static void writeCommitData(String newHash) throws IOException {

/**
* Deletes all directories (not files) inside of the {@link #REPO_DIRECTORY}
* @throws IOException
* @throws IOException
*/
private static void deleteDirectories() throws IOException {
Files.list(REPO_DIRECTORY)
Expand All @@ -140,6 +140,6 @@ record CommitData(String commit, long lastUpdated) {
static final Codec<CommitData> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("commit").forGetter(CommitData::commit),
Codec.LONG.fieldOf("lastUpdated").forGetter(CommitData::lastUpdated))
.apply(instance, CommitData::new));
.apply(instance, CommitData::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.name(Text.translatable("skyblocker.config.foraging.hunting"))

.build())*/

.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class ForagingConfig {
public Hunting hunting = new Hunting();

public static class Hunting {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* HUD render events that allow for proper layering between different HUD elements.
* This should always be preferred over Fabric's {@link net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback}.
*
*
* Perhaps in the future this system could be PR'd to Fabric.
*/
public class HudRenderEvents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.mojang.brigadier.context.CommandContext;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected Boolean isMatch(String inputString) {
}

return false;
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class Kuudra {
public class Kuudra {
public static final int KUUDRA_MAGMA_CUBE_SIZE = 30;

static KuudraPhase phase = KuudraPhase.OTHER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY, float delt
matrices.pop();
}
}

@Override
protected void drawHeaderAndFooterSeparators(DrawContext context) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/**
* The terminal where you change all the panes that are red to green.
*
*
* This doesn't solve the terminal because you don't need a solver for it, but rather to simply allow for click blocking.
*/
public final class LightsOnTerminal extends SimpleContainerSolver implements TerminalSolver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.joml.Vector2ic;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RegisterWidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static boolean shouldDrawMobBoundingBox(Entity entity) {

return false;
}

public static float[] getBoxColor(Entity entity) {
int color = MobGlow.getMobGlow(entity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public final class UltrasequencerSolver extends ExperimentSolver {
public static final UltrasequencerSolver INSTANCE = new UltrasequencerSolver();
/**
* The playable slots of Ultrasequencer in the Metaphysical level.
*
*
* Even though the Supreme/Transcendent levels have less playable slots we filter out black glass panes later on
* since black isn't in the color sequence.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class ModernForagingIsland {

public static void init() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ private static class AnimatedDyeStateTracker {
boolean shouldCycleBack(int samples, boolean canCycleBack) {
return canCycleBack && sampleCounter == samples;
}

int getAndDecrement() {
return sampleCounter--;
}

int getAndIncrement() {
return sampleCounter++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.texture.Sprite;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected DataTooltipInfo(String address, Codec<T> codec, boolean cacheable, BiP
}

@Override
public boolean isDataEnabled() {
public boolean isDataEnabled() {
return dataEnabled.test(ItemTooltip.config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected static ItemStack fromNEUItem(NEUItem item) {

return createErrorStack(item.getSkyblockItemId());
}

private static ItemStack createErrorStack(String skyblockItemId) {
ItemStack errorStack = new ItemStack(Items.BARRIER);
errorStack.set(DataComponentTypes.CUSTOM_NAME, Text.of(skyblockItemId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected void closeRecipeView() {

/**
* Handles updating the search results when a character is typed into the search bar,
*
*
* @implNote The {@code query} is always passed as lower case.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ protected void refreshResults(boolean resetCurrentPage, boolean filteringCraftab

/**
* Sets the "Toggle Craftable" Button texture.
*
*
* No-op as we don't use the button.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static ItemStack getStackFromName(String itemName) {

default -> "NONE";
};

return ItemRepository.getItemStack(itemId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public static void init() {

/**
* Refreshes the token by fetching the player's key pair from the Minecraft Services API.
*
*
* We use the player's uuid, public key, public key signature, public key expiry date, and randomly signed data by the private key to verify the identity/legitimacy
* of the player without the server needing to handle any privileged information.
*
*
* Mojang provides a signature for each key pair which is comprised of the player's uuid, public key, and expiry time so we can easily validate if the key pair
* was generated by Mojang and is tied to said player. For information about what the randomly signed data is used for and why see {@link #getRandomSignedData(PrivateKey)}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/hysky/skyblocker/utils/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class ApiUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ApiUtils.class);
/**
/**
* Do not iterate over this map, it will be accessed and modified by multiple threads.
*/
private static final Object2ObjectOpenHashMap<String, String> NAME_2_UUID_CACHE = new Object2ObjectOpenHashMap<>();
Expand Down
Loading
Loading