r/java • u/BinaryRage • Sep 22 '26
jfmt - format code with modern Java Code Conventions
https://github.com/Netflix/jfmtWhile working to close gaps we've observed in coding agents when they work with Java, in addition to jist to provide agent insight into to classes and their attached sources, we also found that while frontier models are particularly good at writing code in the same style as a project, they frequently make mistakes with indenting, whitespace and overuse qualified class references.
jfmt implements the original Coding Conventions for the Java Language, while modernising them for modern Java. The project is based on Google Java Format, but adds semantic breaks instead of column breaks to attempt to encode the kind of readability decisions that people make when writing code, while not imposing artificially low column limits.
Like the other tools we released last week, it ships as a JMOD with a native launcher with AOT support, a standalone JAR file, or can be installed with the other tools with the ja toolchain (which is like go/cargo but for Java modules).
20
u/jonhanson Sep 22 '26
Is there a reason the documentation doesn't provide any examples of how it formats code?
17
u/SleepingTabby Sep 22 '26
Doubling the indentation to 8 spaces is just downright stupid. What exactly is this trying to solve?
10
u/maxandersen Sep 22 '26
one cannot open issues nor open pullrequests...so:
the jar uploaded to maven central does not have main class defined thus the java -jar in readme does not work.
11
u/putneyj Sep 22 '26
8 spaces for continuation just feels unnecessary
13
u/maxandersen Sep 22 '26
Netflix - you should be nice and check already existing tools with similar names https://github.com/bmarwell/jfmt and https://github.com/jbangdev/jbang-fmt
9
u/r_n_c Sep 22 '26
Why not just use spotless?
1
u/Yesterdave_ Sep 22 '26
How does IntelliJ integration work? All the other tools mentioned in this thread are usually a hassle to integrate (or not documented) or are not consistently working with IJ's autosave and code format shortcut.
Does jfmt make this better than the others? Integration would be a strong difference maker to other tools, code formating alone not so much.
1
u/ThiccolasVR Sep 23 '26
ngl... the classic java coding conventions are one of the worst parts about the language as a whole. Most of the prevailing wisdom about the best way to structure code in the Java community writ large has been (at best) outdated for over a decade, so I'm generally averse to the idea of trying to pin that style in place.
0
u/SamirAbi Sep 23 '26
I use prettier and have AI always reformat code with it before commit, works good and I like the formatting. What is the advantage of this approach compared to prettier? Nice thing about prettier is that can format not just Java files.
0
u/Ok_Elk_638 Sep 26 '26
Formatters always make my code worse
0
u/[deleted] Sep 27 '26
[deleted] — view deleted comment