Skip to content

Commit 432f572

Browse files
committed
style: apply checkstyle fixes and add checkstyle GHA workflow
1 parent 05b3a48 commit 432f572

11 files changed

Lines changed: 100 additions & 26 deletions

File tree

.github/workflows/build.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,26 @@ jobs:
2323
with:
2424
name: Artifacts
2525
path: build/libs/
26+
27+
checkstyle:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout Repository
31+
uses: actions/checkout@v6
32+
- name: Validate Gradle Wrapper
33+
uses: gradle/actions/wrapper-validation@v4
34+
- name: Setup JDK
35+
uses: actions/setup-java@v5
36+
with:
37+
java-version: '25'
38+
distribution: 'microsoft'
39+
- name: Make Gradle Wrapper Executable
40+
run: chmod +x ./gradlew
41+
- name: Run Checkstyle
42+
run: ./gradlew check
43+
- name: Upload Checkstyle Report
44+
uses: actions/upload-artifact@v6
45+
if: always()
46+
with:
47+
name: checkstyle-report
48+
path: build/reports/checkstyle/

src/main/java/org/damon233/performtrackermod/collector/SystemInfoCollector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ private static String getWindowsCpuName() {
152152

153153
private static String getLinuxCpuName() {
154154
String output = readFile("/proc/cpuinfo");
155-
if (output == null) return "Unknown";
155+
if (output == null) {
156+
return "Unknown";
157+
}
156158

157159
for (String line : output.split("\n")) {
158160
line = line.trim();

src/main/java/org/damon233/performtrackermod/command/PtrackerCommand.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,25 @@ public static void register() {
191191
LiteralArgumentBuilder<ServerCommandSource> config = CommandManager.literal("config");
192192
for (ConfigType cfg : ConfigType.values()) {
193193
LiteralArgumentBuilder<ServerCommandSource> item = CommandManager.literal(cfg.key);
194-
item.executes(ctx -> { cfg.sendInfo(ctx.getSource()); return 1; });
194+
item.executes(ctx -> {
195+
cfg.sendInfo(ctx.getSource());
196+
return 1;
197+
});
195198

196199
if (cfg.defaultValue instanceof Integer) {
197200
item.then(CommandManager.argument("value", IntegerArgumentType.integer(1, 3600))
198-
.executes(ctx -> { cfg.setter.accept(IntegerArgumentType.getInteger(ctx, "value")); cfg.sendSuccess(ctx.getSource(), cfg.getter.get()); return 1; }));
201+
.executes(ctx -> {
202+
cfg.setter.accept(IntegerArgumentType.getInteger(ctx, "value"));
203+
cfg.sendSuccess(ctx.getSource(), cfg.getter.get());
204+
return 1;
205+
}));
199206
} else if (cfg.defaultValue instanceof Boolean) {
200207
item.then(CommandManager.argument("value", BoolArgumentType.bool())
201-
.executes(ctx -> { cfg.setter.accept(BoolArgumentType.getBool(ctx, "value")); cfg.sendSuccess(ctx.getSource(), cfg.getter.get()); return 1; }));
208+
.executes(ctx -> {
209+
cfg.setter.accept(BoolArgumentType.getBool(ctx, "value"));
210+
cfg.sendSuccess(ctx.getSource(), cfg.getter.get());
211+
return 1;
212+
}));
202213
} else {
203214
item.then(CommandManager.argument("value", StringArgumentType.string())
204215
.executes(ctx -> {
@@ -220,7 +231,9 @@ public static void register() {
220231
}
221232
config.executes(ctx -> {
222233
ctx.getSource().sendFeedback(() -> Text.literal("=== PerformTracker Config ==="), false);
223-
for (ConfigType cfg : ConfigType.values()) cfg.sendLine(ctx.getSource());
234+
for (ConfigType cfg : ConfigType.values()) {
235+
cfg.sendLine(ctx.getSource());
236+
}
224237
ctx.getSource().sendFeedback(() -> Text.literal("======================="), false);
225238
ctx.getSource().sendFeedback(() -> Text.translatable("performtracker.config.usage"), false);
226239
return 1;

src/main/java/org/damon233/performtrackermod/config/ConfigAccess.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ public static void setOutputFormat(String format) {
231231
}
232232

233233
private static String normalizeOutputFormat(String format) {
234-
if (format == null) return null;
234+
if (format == null) {
235+
return null;
236+
}
235237
String lower = format.toLowerCase().trim();
236238
if (lower.equals("csv") || lower.equals("json") || lower.equals("yaml")) {
237239
return lower;

src/main/java/org/damon233/performtrackermod/controller/TrackerController.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,18 @@ private MutableText buildChatMessage(PerformanceMetrics metrics) {
261261

262262
MutableText result = Text.empty();
263263
for (int i = 0; i < chatMessagePartCount; i++) {
264-
if (i > 0) result = result.append(Text.literal(" | ").withColor(0x888888));
264+
if (i > 0) {
265+
result = result.append(Text.literal(" | ").withColor(0x888888));
266+
}
265267
result = result.append(chatMessageParts[i]);
266268
}
267269
return result;
268270
}
269271

270272
private void addChatPart(String label, String value) {
271-
if (chatMessagePartCount >= chatMessageParts.length) return;
273+
if (chatMessagePartCount >= chatMessageParts.length) {
274+
return;
275+
}
272276
chatMessageParts[chatMessagePartCount++] = Text.literal(label).withColor(0x888888).append(TranslationService.colorValue(value));
273277
}
274278

src/main/java/org/damon233/performtrackermod/data/PerformanceMetrics.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public record PerformanceMetrics(
3434
mspt = Math.max(0.0, mspt);
3535
heapUsed = Math.max(0.0, heapUsed);
3636
heapMax = Math.max(0.0, heapMax);
37-
if (cpuUsage < 0) cpuUsage = -1.0;
37+
if (cpuUsage < 0) {
38+
cpuUsage = -1.0;
39+
}
3840
}
3941

4042
public static String formatValue(double value) {

src/main/java/org/damon233/performtrackermod/network/JsonFormatter.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,31 @@ public static String formatMetrics(long timestamp, String sessionId,
3737
first = false;
3838
}
3939
if (collectTps) {
40-
if (!first) sb.append(',');
40+
if (!first) {
41+
sb.append(',');
42+
}
4143
sb.append("\"tps\":").append(tps);
4244
first = false;
4345
}
4446
if (collectMspt) {
45-
if (!first) sb.append(',');
47+
if (!first) {
48+
sb.append(',');
49+
}
4650
sb.append("\"mspt\":").append(mspt);
4751
first = false;
4852
}
4953
if (collectHeap) {
50-
if (!first) sb.append(',');
54+
if (!first) {
55+
sb.append(',');
56+
}
5157
sb.append("\"heapUsed\":").append(heapUsed);
5258
sb.append(",\"heapMax\":").append(heapMax);
5359
first = false;
5460
}
5561
if (collectCpu) {
56-
if (!first) sb.append(',');
62+
if (!first) {
63+
sb.append(',');
64+
}
5765
sb.append("\"cpu\":").append(cpuUsage);
5866
}
5967
sb.append("}}");
@@ -62,7 +70,9 @@ public static String formatMetrics(long timestamp, String sessionId,
6270
}
6371

6472
public static String escapeJson(String s) {
65-
if (s == null) return "";
73+
if (s == null) {
74+
return "";
75+
}
6676
return s.replace("\\", "\\\\")
6777
.replace("\"", "\\\"")
6878
.replace("\n", "\\n")

src/main/java/org/damon233/performtrackermod/utils/CharsetDetector.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public static Charset detect() {
7171

7272
private static Charset detectWindows() {
7373
String codepage = runCommand("chcp");
74-
if (codepage == null) return null;
74+
if (codepage == null) {
75+
return null;
76+
}
7577

7678
try {
7779
String num = codepage.replaceAll("[^0-9]", "");
@@ -83,18 +85,20 @@ private static Charset detectWindows() {
8385
}
8486

8587
private static Charset detectLinux() {
86-
// Check LANG env var first (fast, no subprocess)
8788
String locale = System.getenv("LANG");
8889
Charset charset = parseLocaleToCharset(locale);
89-
if (charset != null) return charset;
90+
if (charset != null) {
91+
return charset;
92+
}
9093

91-
// Fallback to locale charmap command
9294
locale = runCommand("locale charmap");
9395
return parseLocaleToCharset(locale);
9496
}
9597

9698
static Charset parseLocaleToCharset(String locale) {
97-
if (locale == null) return null;
99+
if (locale == null) {
100+
return null;
101+
}
98102

99103
locale = locale.trim().toUpperCase();
100104
if (locale.contains("UTF-8") || locale.contains("UTF8")) {

src/main/java/org/damon233/performtrackermod/writer/CsvWriter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ protected String getThreadName() {
3939

4040
@Override
4141
public void writeHeader(String... headers) throws IOException {
42-
if (headerWritten || writer == null) return;
42+
if (headerWritten || writer == null) {
43+
return;
44+
}
4345

4446
StringBuilder sb = new StringBuilder("unix_timestamp");
45-
for (String h : headers) sb.append(",").append(h);
47+
for (String h : headers) {
48+
sb.append(",").append(h);
49+
}
4650
writer.write(sb.toString());
4751
writer.newLine();
4852
headerWritten = true;

src/main/java/org/damon233/performtrackermod/writer/JsonWriter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ protected void flushInternal() throws IOException {
8888

8989
private Object formatValue(Object v) {
9090
if (v instanceof Double d) {
91-
if (Double.isNaN(d)) return null;
92-
if (Double.isInfinite(d)) return "infinite";
91+
if (Double.isNaN(d)) {
92+
return null;
93+
}
94+
if (Double.isInfinite(d)) {
95+
return "infinite";
96+
}
9397
return d;
9498
}
9599
return v;

0 commit comments

Comments
 (0)