-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeShittifier.java
More file actions
500 lines (411 loc) · 17.8 KB
/
CodeShittifier.java
File metadata and controls
500 lines (411 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
package com.bankalfalah.alfapay.utils;
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.regex.*;
import java.util.stream.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* CodeShittifier - Making your code shittier.
*
* A satirical code formatter that does the exact opposite of Prettier/ktfmt.
* Embraces chaos, messiness, and confusion in your Java/Kotlin codebase.
*
* WARNING: This is a parody tool. Do NOT use on production code!
* Always commit your code before running this tool.
*
* @author Sarmad
* @version 1.0.0 (Chaos Edition)
*/
public class CodeShittifier {
private static final Random random = new Random();
// Configuration
private boolean dryRun = false;
private boolean createBackups = true;
private int shittificationLevel = 5; // 1-10, where 10 is maximum chaos
private boolean verbose = false;
private Path backupPath = null;
// Statistics
private int filesProcessed = 0;
private int filesShittified = 0;
private int linesShittified = 0;
public static void main(String[] args) {
if (args.length == 0) {
printUsage();
return;
}
CodeShittifier shittifier = new CodeShittifier();
shittifier.parseArgs(args);
String targetPath = args[args.length - 1];
Path path = Paths.get(targetPath);
if (!Files.exists(path)) {
System.err.println("Error: Path does not exist: " + targetPath);
System.exit(1);
}
System.out.println("CodeShittifier v1.0.0 - Making Code Great Again (But Shittier)");
System.out.println("-".repeat(80));
System.out.println("Target: " + path.toAbsolutePath());
System.out.println("Shittification Level: " + shittifier.shittificationLevel + "/10");
System.out.println("Dry Run: " + (shittifier.dryRun ? "Yes (no files will be modified)" : "No"));
System.out.println("Backups: " + (shittifier.createBackups ? "Enabled" : "Disabled"));
System.out.println("-".repeat(80));
try {
// Create backup before processing
if (shittifier.createBackups && !shittifier.dryRun) {
shittifier.createBackupFolder(path);
}
shittifier.processPath(path);
shittifier.printStatistics();
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
private void createBackupFolder(Path targetPath) throws IOException {
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
String backupFolderName = targetPath.getFileName() + "_backup_" + timestamp;
Path parentDir = targetPath.getParent();
if (parentDir == null) {
parentDir = Paths.get(".");
}
backupPath = parentDir.resolve(backupFolderName);
System.out.println("Creating backup: " + backupPath.toAbsolutePath());
// Copy entire directory
copyDirectory(targetPath, backupPath);
System.out.println("Backup created successfully!");
System.out.println("-".repeat(80));
}
private void copyDirectory(Path source, Path target) throws IOException {
Files.walk(source)
.forEach(sourcePath -> {
try {
Path targetPath = target.resolve(source.relativize(sourcePath));
if (Files.isDirectory(sourcePath)) {
Files.createDirectories(targetPath);
} else {
Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
private void parseArgs(String[] args) {
for (int i = 0; i < args.length - 1; i++) {
switch (args[i]) {
case "--dry-run":
case "-d":
dryRun = true;
break;
case "--no-backup":
createBackups = false;
break;
case "--level":
case "-l":
if (i + 1 < args.length - 1) {
shittificationLevel = Math.max(1, Math.min(10, Integer.parseInt(args[++i])));
}
break;
case "--verbose":
case "-v":
verbose = true;
break;
}
}
}
private void processPath(Path path) throws IOException {
if (Files.isDirectory(path)) {
try (Stream<Path> paths = Files.walk(path)) {
paths.filter(Files::isRegularFile)
.filter(this::isJavaOrKotlinFile)
.forEach(this::shittifyFile);
}
} else if (isJavaOrKotlinFile(path)) {
shittifyFile(path);
}
}
private boolean isJavaOrKotlinFile(Path path) {
String fileName = path.getFileName().toString().toLowerCase();
return fileName.endsWith(".java") || fileName.endsWith(".kt");
}
private void shittifyFile(Path filePath) {
filesProcessed++;
try {
String originalContent = Files.readString(filePath);
String shittifiedContent = applyShittification(originalContent);
if (!originalContent.equals(shittifiedContent)) {
filesShittified++;
if (verbose) {
System.out.println("Shittifying: " + filePath);
}
if (!dryRun) {
Files.writeString(filePath, shittifiedContent);
}
linesShittified += shittifiedContent.split("\n").length;
} else if (verbose) {
System.out.println("Skipping: " + filePath + " (no changes)");
}
} catch (IOException e) {
System.err.println("Failed to process: " + filePath);
if (verbose) {
e.printStackTrace();
}
}
}
private String applyShittification(String content) {
String result = content;
// Apply various shittification strategies based on level
result = randomizeIndentation(result);
result = messUpSpacing(result);
if (shittificationLevel >= 3) {
result = randomizeBraceStyle(result);
}
if (shittificationLevel >= 5) {
result = addRandomBlankLines(result);
result = removeUsefulBlankLines(result);
}
if (shittificationLevel >= 7) {
result = randomizeOperatorSpacing(result);
result = addTrailingSpaces(result);
}
if (shittificationLevel >= 9) {
result = maxChaosMode(result);
}
return result;
}
private String randomizeIndentation(String content) {
String[] lines = content.split("\n", -1);
StringBuilder result = new StringBuilder();
for (String line : lines) {
if (line.trim().isEmpty()) {
result.append(line).append("\n");
continue;
}
// Get original indentation level
int originalIndent = line.length() - line.stripLeading().length();
String trimmedLine = line.stripLeading();
// Randomly choose between tabs and spaces
String indentation;
if (random.nextBoolean()) {
// Use spaces with random count
int spaces = random.nextInt(Math.max(1, originalIndent + 3));
indentation = " ".repeat(spaces);
} else {
// Use tabs with random count
int tabs = random.nextInt(Math.max(1, (originalIndent / 4) + 2));
indentation = "\t".repeat(tabs);
}
// Sometimes mix tabs and spaces for maximum chaos
if (random.nextInt(100) < shittificationLevel * 5) {
indentation = mixTabsAndSpaces(indentation);
}
result.append(indentation).append(trimmedLine).append("\n");
}
return result.toString();
}
private String mixTabsAndSpaces(String indentation) {
StringBuilder mixed = new StringBuilder();
for (char c : indentation.toCharArray()) {
if (random.nextBoolean()) {
mixed.append(c);
} else {
mixed.append(c == '\t' ? " " : "\t");
}
}
return mixed.toString();
}
private String messUpSpacing(String content) {
// Add or remove spaces around various elements
Pattern pattern = Pattern.compile("([,;])");
Matcher matcher = pattern.matcher(content);
StringBuffer result = new StringBuffer();
while (matcher.find()) {
String char_ = matcher.group(1);
int spaces = random.nextInt(4);
String replacement;
if (random.nextBoolean()) {
replacement = char_ + " ".repeat(spaces);
} else {
replacement = " ".repeat(spaces) + char_;
}
matcher.appendReplacement(result, Matcher.quoteReplacement(replacement));
}
matcher.appendTail(result);
return result.toString();
}
private String randomizeBraceStyle(String content) {
// Sometimes put opening braces on same line, sometimes on new line
String[] lines = content.split("\n", -1);
StringBuilder result = new StringBuilder();
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
// Find lines that might have braces
if (line.contains("{")) {
if (random.nextInt(100) < 40) {
// Move brace to next line
String beforeBrace = line.substring(0, line.indexOf("{")).trim();
String afterBrace = line.substring(line.indexOf("{") + 1);
result.append(beforeBrace).append("\n");
result.append(" ".repeat(random.nextInt(8))).append("{");
if (!afterBrace.trim().isEmpty()) {
result.append(afterBrace);
}
result.append("\n");
continue;
}
}
result.append(line).append("\n");
}
return result.toString();
}
private String addRandomBlankLines(String content) {
String[] lines = content.split("\n", -1);
StringBuilder result = new StringBuilder();
for (String line : lines) {
// Randomly add 0-3 blank lines before this line
if (random.nextInt(100) < shittificationLevel * 3) {
int blankLines = random.nextInt(4);
result.append("\n".repeat(blankLines));
}
result.append(line).append("\n");
}
return result.toString();
}
private String removeUsefulBlankLines(String content) {
// Remove intentional blank lines between methods/classes
content = content.replaceAll("\n\n\n+", "\n");
// Sometimes remove blank lines completely
if (random.nextInt(100) < shittificationLevel * 2) {
content = content.replaceAll("\n\n", "\n");
}
return content;
}
private String randomizeOperatorSpacing(String content) {
// Mess up spacing around operators
String[] operators = {"+", "-", "*", "/", "=", "==", "!=", "&&", "||", "<", ">", "<=", ">="};
for (String op : operators) {
String escaped = Pattern.quote(op);
Pattern pattern = Pattern.compile("\\s*" + escaped + "\\s*");
Matcher matcher = pattern.matcher(content);
StringBuffer result = new StringBuffer();
while (matcher.find()) {
int leftSpaces = random.nextInt(4);
int rightSpaces = random.nextInt(4);
String replacement = " ".repeat(leftSpaces) + op + " ".repeat(rightSpaces);
matcher.appendReplacement(result, Matcher.quoteReplacement(replacement));
}
matcher.appendTail(result);
content = result.toString();
}
return content;
}
private String addTrailingSpaces(String content) {
String[] lines = content.split("\n", -1);
StringBuilder result = new StringBuilder();
for (String line : lines) {
result.append(line);
// Add random trailing spaces
if (random.nextInt(100) < shittificationLevel * 8) {
result.append(" ".repeat(random.nextInt(10)));
}
result.append("\n");
}
return result.toString();
}
private String maxChaosMode(String content) {
// Ultimate chaos: randomly break lines (but not critical ones)
String[] lines = content.split("\n", -1);
StringBuilder result = new StringBuilder();
for (String line : lines) {
String trimmedLine = line.trim();
// NEVER break these critical lines
if (trimmedLine.startsWith("package ") ||
trimmedLine.startsWith("import ") ||
trimmedLine.startsWith("@") ||
trimmedLine.startsWith("//") ||
trimmedLine.startsWith("/*") ||
trimmedLine.startsWith("*") ||
trimmedLine.contains("\"") || // Lines with strings
line.length() <= 40) {
result.append(line).append("\n");
continue;
}
// Only break long, safe lines (method calls, conditions, etc.)
if (random.nextInt(100) < 30) {
// Find a safe break point (after operators, commas, parentheses)
int breakPoint = findSafeBreakPoint(line);
if (breakPoint > 0 && breakPoint < line.length() - 1) {
result.append(line.substring(0, breakPoint)).append("\n");
result.append(" ".repeat(random.nextInt(15)));
result.append(line.substring(breakPoint).trim()).append("\n");
} else {
result.append(line).append("\n");
}
} else {
result.append(line).append("\n");
}
}
return result.toString();
}
private int findSafeBreakPoint(String line) {
// Find safe break points: after operators, commas, semicolons, opening braces
char[] safeBreakChars = {',', ';', '{', '(', '&', '|', '+', '-', '*', '/'};
// Look for break points in the middle section of the line
int minBreak = line.length() / 3;
int maxBreak = (2 * line.length()) / 3;
for (int i = maxBreak; i >= minBreak; i--) {
char c = line.charAt(i);
for (char breakChar : safeBreakChars) {
if (c == breakChar) {
return i + 1; // Break after the character
}
}
}
return -1; // No safe break point found
}
private void printStatistics() {
System.out.println("\n" + "-".repeat(80));
System.out.println("Shittification Complete!");
System.out.println("-".repeat(80));
System.out.println("Files Scanned: " + filesProcessed);
System.out.println("Files Shittified: " + filesShittified);
System.out.println("Lines Affected: " + linesShittified);
if (dryRun) {
System.out.println("\nThis was a dry run. No files were actually modified.");
} else if (createBackups && backupPath != null) {
System.out.println("\nBackup folder created at: " + backupPath.toAbsolutePath());
}
System.out.println("\nYour code is now officially shittier! Enjoy the chaos!");
System.out.println("-".repeat(80));
}
private static void printUsage() {
System.out.println("""
CodeShittifier - Making Code Shittier Since 2026
Usage: java CodeShittifier [OPTIONS] <path>
Options:
-d, --dry-run Show what would be changed without modifying files
--no-backup Don't create backup folder (dangerous!)
-l, --level <1-10> Shittification level (default: 5)
-v, --verbose Show detailed output
Examples:
# Dry run to see what would happen
java CodeShittifier --dry-run ./src
# Shittify with medium chaos
java CodeShittifier --level 5 ./src/main/java
# Maximum chaos mode (YOLO)
java CodeShittifier --level 10 ./myproject
# Process a single file
java CodeShittifier MyClass.java
WARNING: This is a parody tool for educational/entertainment purposes.
Always commit your code before running this tool!
The maintainers are not responsible for any tears, rage quits,
or team members questioning your sanity.
Remember: With great power comes great responsibility to make code shittier!
""");
}
}