Skip to content

Commit ebfb3dd

Browse files
committed
Add Spotless and Checkstyle
1 parent eab2c9e commit ebfb3dd

File tree

78 files changed

+992
-792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+992
-792
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
!/LICENSE
1919
!/README.md
2020
!/settings.gradle
21+
!/checkstyle.xml
2122

2223
# Build Src
2324
!/buildSrc

build.gradle

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ plugins {
22
id 'fabric-loom' version "${loom_version}"
33
id 'maven-publish'
44
id 'net.azureaaron.mod.annotation-processor'
5+
id "com.diffplug.spotless" version "${spotless_version}"
6+
id "checkstyle"
57
}
68

79
version = "${project.mod_version}+${project.minecraft_version}"
@@ -87,7 +89,7 @@ dependencies {
8789
include modImplementation("net.azureaaron:hm-api:${hm_api_version}")
8890

8991
include implementation("net.azureaaron:networth-calculator:${networth_calculator_version}")
90-
92+
9193
include implementation("net.azureaaron:legacy-item-dfu:${legacy_item_dfu_version}")
9294

9395
// Fabric Language Kotlin for using MoulConfig - we are still a Java-exclusive mod
@@ -141,6 +143,30 @@ jar {
141143
}
142144
}
143145

146+
spotless {
147+
lineEndings = com.diffplug.spotless.LineEnding.UNIX
148+
149+
java {
150+
removeUnusedImports()
151+
leadingSpacesToTabs()
152+
trimTrailingWhitespace()
153+
endWithNewline()
154+
}
155+
156+
groovyGradle {
157+
target 'src/**/*.gradle', '*.gradle', 'gradle/*.gradle'
158+
greclipse().configProperties \
159+
'groovy.formatter.multiline.indentation=2', // Default
160+
'groovy.formatter.line.maxlength=999',
161+
'groovy.formatter.longListLength=999',
162+
'groovy.formatter.remove.unnecessary.semicolons=true'
163+
}
164+
}
165+
166+
checkstyle {
167+
toolVersion = "${checkstyle_version}"
168+
configFile = rootProject.file("checkstyle.xml")
169+
}
144170

145171
// configure the maven publication
146172
publishing {

checkstyle.xml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "https://www.puppycrawl.com/dtds/configuration_1_3.dtd">
3+
<module name="Checker">
4+
<property name="charset" value="UTF-8"/>
5+
<property name="fileExtensions" value="java"/>
6+
<property name="localeLanguage" value="en"/>
7+
<property name="localeCountry" value="CA"/>
8+
<property name="tabWidth" value="4"/>
9+
10+
<module name="NewlineAtEndOfFile"/>
11+
12+
<!-- Disallow trailing whitespace -->
13+
<module name="RegexpSingleline">
14+
<property name="format" value="\s+$"/>
15+
<property name="message" value="trailing whitespace"/>
16+
</module>
17+
18+
<module name="TreeWalker">
19+
<!-- Allow "//CHECKSTYLE.OFF: <InspectionName>" and "//CHECKSTYLE.ON: <InspectionName>" pairs to toggle some inspections -->
20+
<module name="SuppressionCommentFilter">
21+
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
22+
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
23+
<property name="checkFormat" value="$1"/>
24+
</module>
25+
26+
<!-- Ensure all imports are ship shape -->
27+
<module name="AvoidStarImport"/>
28+
<module name="IllegalImport"/>
29+
<module name="RedundantImport"/>
30+
<module name="UnusedImports"/>
31+
32+
<module name="SeparatorWrap">
33+
<property name="tokens" value="DOT,ELLIPSIS,AT"/>
34+
<property name="option" value="nl"/>
35+
</module>
36+
<module name="SeparatorWrap">
37+
<property name="tokens" value="COMMA,SEMI"/>
38+
<property name="option" value="eol"/>
39+
</module>
40+
41+
<module name="ParenPad"/>
42+
<module name="NoWhitespaceBefore"/>
43+
<module name="NoWhitespaceAfter">
44+
<!-- Allow ARRAY_INIT -->
45+
<property name="tokens" value="AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP"/>
46+
</module>
47+
<module name="WhitespaceAfter"/>
48+
<module name="WhitespaceAround">
49+
<!-- Allow PLUS, MINUS, STAR, DIV as they may be more readable without spaces in some cases -->
50+
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV_ASSIGN,DO_WHILE,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
51+
<property name="allowEmptyCatches" value="true"/>
52+
<property name="allowEmptyConstructors" value="true"/>
53+
<property name="allowEmptyLambdas" value="true"/>
54+
<property name="allowEmptyLoops" value="true"/>
55+
<property name="allowEmptyMethods" value="true"/>
56+
<property name="allowEmptySwitchBlockStatements" value="true"/>
57+
<property name="allowEmptyTypes" value="true"/>
58+
</module>
59+
<module name="GenericWhitespace"/>
60+
61+
<module name="ArrayTypeStyle"/>
62+
<module name="DefaultComesLast">
63+
<property name="skipIfLastAndSharedWithCase" value="true"/>
64+
</module>
65+
<module name="SimplifyBooleanExpression"/>
66+
<module name="SimplifyBooleanReturn"/>
67+
<module name="StringLiteralEquality"/>
68+
<module name="EqualsHashCode"/>
69+
70+
<module name="HexLiteralCase"/>
71+
<module name="UpperEll"/>
72+
73+
<module name="ModifierOrder"/>
74+
<module name="RedundantModifier"/>
75+
76+
<module name="AnnotationLocation"/>
77+
<module name="MissingOverride"/>
78+
79+
<!-- Enforce tabs -->
80+
<module name="RegexpSinglelineJava">
81+
<property name="format" value="^\t* ([^*]|\*[^ /])"/>
82+
<property name="message" value="non-tab indentation"/>
83+
</module>
84+
85+
<module name="OuterTypeFilename"/>
86+
<module name="PackageDeclaration"/>
87+
88+
<module name="InvalidJavadocPosition"/>
89+
<module name="AtclauseOrder"/>
90+
91+
<!-- Prevent non-@Unique fields in Mixin classes -->
92+
<module name="MatchXpath">
93+
<property name="query" value="
94+
//OBJBLOCK/VARIABLE_DEF[
95+
not(
96+
./MODIFIERS/ANNOTATION/IDENT[
97+
@text='Unique'
98+
or @text='Shadow'
99+
]
100+
)
101+
and
102+
../../../CLASS_DEF[
103+
./MODIFIERS/ANNOTATION/IDENT[@text='Mixin']
104+
]
105+
]
106+
"/>
107+
<message key="matchxpath.match" value="Mixin fields must be annotated with @Unique or @Shadow"/>
108+
</module>
109+
110+
<!-- Prevent non-@Unique methods in Mixin classes -->
111+
<!-- All Mixin and MixinExtras annotations must be listed here -->
112+
<module name="MatchXpath">
113+
<property name="query" value="
114+
//METHOD_DEF[
115+
not(
116+
./MODIFIERS/ANNOTATION/IDENT[
117+
@text='Unique'
118+
or @text='Inject'
119+
or @text='ModifyArg'
120+
or @text='ModifyExpressionValue'
121+
or @text='ModifyReceiver'
122+
or @text='ModifyReturnValue'
123+
or @text='ModifyVariable'
124+
or @text='Override'
125+
or @text='Overwrite'
126+
or @text='Redirect'
127+
or @text='Shadow'
128+
or @text='WrapMethod'
129+
or @text='WrapOperation'
130+
or @text='WrapWithCondition'
131+
]
132+
)
133+
and
134+
../../../CLASS_DEF[
135+
./MODIFIERS/ANNOTATION/IDENT[@text='Mixin']
136+
]
137+
]
138+
"/>
139+
<message key="matchxpath.match" value="Mixin methods must be annotated with @Unique or one of the Mixin annotations"/>
140+
</module>
141+
142+
<!-- Prevent @Inject local capture, @Local is preferred -->
143+
<module name="MatchXpath">
144+
<property name="query" value="
145+
//METHOD_DEF[
146+
./MODIFIERS/ANNOTATION[
147+
./IDENT[@text='Inject']
148+
and
149+
./ANNOTATION_MEMBER_VALUE_PAIR/IDENT[@text='locals']
150+
]
151+
]
152+
"/>
153+
<message key="matchxpath.match" value="Inject local capture is not allowed, use @Local instead"/>
154+
</module>
155+
156+
<!-- Prevent String#toLowerCase/toUpperCase without a given Locale to prevent localization issues -->
157+
<!-- Not specifying a locale is error prone as it can easily lead to silent breakages with some locales! -->
158+
<module name = "MatchXpath">
159+
<property name="query" value="//METHOD_CALL[./DOT/IDENT[@text='toLowerCase' or @text='toUpperCase']]/ELIST[count(./*) = 0]"/>
160+
<message key="matchxpath.match" value="String#toLowerCase/toUpperCase calls must specify a locale, English recommended"/>
161+
</module>
162+
</module>
163+
</module>

gradle.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ org.gradle.configuration-cache=false
2323
modmenu_version=16.0.0-rc.1
2424
hm_api_version=1.0.1+1.21.2
2525
networth_calculator_version=1.0.5
26-
legacy_item_dfu_version=1.0.3+1.21.5
26+
legacy_item_dfu_version=1.0.3+1.21.5
27+
28+
# Miscellaneous
29+
spotless_version=8.0.0
30+
checkstyle_version=12.1.1

settings.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
pluginManagement {
2-
repositories {
3-
maven {
4-
name = 'Fabric'
5-
url = 'https://maven.fabricmc.net/'
6-
}
7-
mavenCentral()
8-
gradlePluginPortal()
9-
}
2+
repositories {
3+
maven {
4+
name = 'Fabric'
5+
url = 'https://maven.fabricmc.net/'
6+
}
7+
mavenCentral()
8+
gradlePluginPortal()
9+
}
1010
}

src/main/java/net/azureaaron/mod/Colour.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,36 @@
1010

1111
public class Colour {
1212
private static final Supplier<GeneralConfig.CustomColourProfile> CUSTOM = () -> AaronModConfigManager.get().general.customColourProfile;
13-
public static final int WARNING = 0xeac864;
14-
public static final int INFO = 0x218bff;
13+
public static final int WARNING = 0xEAC864;
14+
public static final int INFO = 0x218BFF;
1515
//google search: good colour combinations
1616
//https://primer.style/prism
17-
17+
1818
public enum ColourProfiles {
19-
Original(0xe14212, 0xeac54f, 0xfb8f44, 0xfa4549, 0xd0d7de, 0x8c959f), //Original
20-
Midnight(0x6639ba, 0x0550ae, 0xa475f9, 0xeac54f, 0xd0d7de, 0x8c959f), //Purple-Blue one
21-
Earth(0x1a7f37, 0x0969da, 0x4ac26b, 0x754d43, 0xd0d7de, 0x8c959f), //Lighter Blue's and Greens
22-
Sakura(0xbf3989, 0xcf222e, 0xff80c8, 0xf6f8fa, 0xd0d7de, 0x8c959f), //Pink with maybe some reds?
23-
Cloudy(0x6e7781, 0xeaeef2, 0x8c959f, 0x24292f, 0xd0d7de, 0x424a53),
24-
Halloween(0xe45600, 0x57606a, 0x8896a5, 0xd1d7df, 0xeaeef2, 0x8c959f),
25-
Christmas(0xcf222e, 0x116329, 0xf6f8fa, 0xfa4549, 0xd0d7de, 0x8c959f),
26-
Candyland(0xffb3b3, 0xffec8b, 0x99d9ea, 0xf08080, 0xffe4e1, 0xc2c2f0),
27-
Cyberpunk(0x007bff, 0x00cec9, 0x28a745, 0xff9933, 0x343a40, 0xeaecee),
28-
Lava(0xff0000, 0xff9933, 0xffd700, 0xf0e68c, 0x696969, 0xf5f5f5),
29-
Ocean(0x007bff, 0x3498db, 0x474747, 0x28a745, 0xc2c2f0, 0xe0e0e0),
19+
Original(0xE14212, 0xEAC54F, 0xFB8F44, 0xFA4549, 0xD0D7DE, 0x8C959F), //Original
20+
Midnight(0x6639BA, 0x0550AE, 0xA475F9, 0xEAC54F, 0xD0D7DE, 0x8C959F), //Purple-Blue one
21+
Earth(0x1A7F37, 0x0969DA, 0x4AC26B, 0x754D43, 0xD0D7DE, 0x8C959F), //Lighter Blue's and Greens
22+
Sakura(0xBF3989, 0xCF222E, 0xFF80C8, 0xF6F8FA, 0xD0D7DE, 0x8C959F), //Pink with maybe some reds?
23+
Cloudy(0x6E7781, 0xEAEEF2, 0x8C959F, 0x24292F, 0xD0D7DE, 0x424A53),
24+
Halloween(0xE45600, 0x57606A, 0x8896A5, 0xD1D7DF, 0xEAEEF2, 0x8C959F),
25+
Christmas(0xCF222E, 0x116329, 0xF6F8FA, 0xFA4549, 0xD0D7DE, 0x8C959F),
26+
Candyland(0xFFB3B3, 0xFFEC8B, 0x99D9EA, 0xF08080, 0xFFE4E1, 0xC2C2F0),
27+
Cyberpunk(0x007BFF, 0x00CEC9, 0x28A745, 0xFF9933, 0x343A40, 0xEAECEE),
28+
Lava(0xFF0000, 0xFF9933, 0xFFD700, 0xF0E68C, 0x696969, 0xF5F5F5),
29+
Ocean(0x007BFF, 0x3498DB, 0x474747, 0x28A745, 0xC2C2F0, 0xE0E0E0),
3030
Custom(() -> CUSTOM.get().primaryColour.getRGB(), () -> CUSTOM.get().secondaryColour.getRGB(), () -> CUSTOM.get().infoColour.getRGB(), () -> CUSTOM.get().highlightColour.getRGB(), () -> CUSTOM.get().hoverColour.getRGB(), () -> CUSTOM.get().supportingInfoColour.getRGB());
31-
31+
3232
public final IntSupplier primaryColour;
3333
public final IntSupplier secondaryColour;
3434
public final IntSupplier infoColour;
3535
public final IntSupplier highlightColour;
3636
public final IntSupplier hoverColour;
3737
public final IntSupplier supportingInfoColour;
38-
38+
3939
ColourProfiles(int primaryColour, int secondaryColour, int infoColour, int highlightColour, int hoverColour, int supportingInfoColour) {
4040
this(() -> primaryColour, () -> secondaryColour, () -> infoColour, () -> highlightColour, () -> hoverColour, () -> supportingInfoColour);
4141
}
42-
42+
4343
ColourProfiles(IntSupplier primaryColour, IntSupplier secondaryColour, IntSupplier infoColour, IntSupplier highlightColour, IntSupplier hoverColour, IntSupplier supportingInfoColour) {
4444
this.primaryColour = primaryColour;
4545
this.secondaryColour = secondaryColour;
@@ -48,28 +48,28 @@ public enum ColourProfiles {
4848
this.hoverColour = hoverColour;
4949
this.supportingInfoColour = supportingInfoColour;
5050
}
51-
51+
5252
public int gradient(double percentage) {
5353
return OkLabColour.interpolate(primaryColour.getAsInt(), secondaryColour.getAsInt(), (float) percentage);
5454
}
5555
}
56-
56+
5757
//Credit to https://codepen.io/OliverBalfour/post/programmatically-making-gradients
5858
public static int interpolate(int firstColour, int secondColour, double percentage) {
5959
int r1 = MathHelper.square((firstColour >> 16) & 0xFF);
6060
int g1 = MathHelper.square((firstColour >> 8) & 0xFF);
6161
int b1 = MathHelper.square(firstColour & 0xFF);
62-
62+
6363
int r2 = MathHelper.square((secondColour >> 16) & 0xFF);
6464
int g2 = MathHelper.square((secondColour >> 8) & 0xFF);
6565
int b2 = MathHelper.square(secondColour & 0xFF);
66-
66+
6767
double inverse = 1d - percentage;
68-
68+
6969
int r3 = (int) Math.floor(Math.sqrt(r1 * inverse + r2 * percentage));
7070
int g3 = (int) Math.floor(Math.sqrt(g1 * inverse + g2 * percentage));
7171
int b3 = (int) Math.floor(Math.sqrt(b1 * inverse + b2 * percentage));
72-
73-
return (r3 << 16) | (g3 << 8 ) | b3;
72+
73+
return (r3 << 16) | (g3 << 8) | b3;
7474
}
7575
}

src/main/java/net/azureaaron/mod/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private static void tick(MinecraftClient client) {
5151
/**
5252
* The content of this method is completely overwritten by ASM at compile time, any statements added to this method will do nothing.
5353
* To initialize your class, annotate its initializer method with {@code @Init}
54-
*
54+
*
5555
* @see Init
5656
*/
5757
private static void init() {}

src/main/java/net/azureaaron/mod/commands/ClientTextArgumentType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public class ClientTextArgumentType implements ArgumentType<Text> {
2323
public static final DynamicCommandExceptionType INVALID_COMPONENT_EXCEPTION = new DynamicCommandExceptionType(
2424
text -> Text.translatable("argument.component.invalid", text));
2525
private static final Parser<NbtElement> PARSER = SnbtParsing.createParser(NbtOps.INSTANCE);
26-
26+
2727
private ClientTextArgumentType() {}//TextArgumentType
28-
28+
2929
public static Text getTextArgument(CommandContext<FabricClientCommandSource> context, String name) {
3030
return context.getArgument(name, Text.class);
3131
}
@@ -46,7 +46,7 @@ public Text parse(StringReader stringReader) throws CommandSyntaxException {
4646
}
4747
// Since everything was successful we'll pretend to have read everything
4848
stringReader.setCursor(stringReader.getString().length());
49-
49+
5050
return text;
5151
} catch (Exception exception) {
5252
String string = exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage();

src/main/java/net/azureaaron/mod/commands/CommandPlayerData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Record which holds a player's name and uuid, similar to a {@link com.mojang.authlib.GameProfile GameProfile}.
88
* This is used for commands that take in a player argument.
9-
*
9+
*
1010
* @author Aaron
1111
*/
1212
record CommandPlayerData(String name, String id) {

0 commit comments

Comments
 (0)