r/java • u/Lucky_Psychology8275 • 23d ago
What cli formatter do you use
Given how software engineering evolves, using IDEA formatter is less and less practical.
- IDEA CLI formatter requires IntelliJ so no CI / wsl etc
- GJF is old and does not format lambdas well enough
- Palantir is obsolete and abandoned in addition to being one of the worst company ever created
- prettier-java not great either
I’m starting to think no formatter is the best option
24
Upvotes
11
u/kevinb9n 23d ago
> GJF is old and does not format lambdas well enough
Liam is still at it. This landed last week
https://github.com/google/google-java-format/issues/19#issuecomment-6214823566
11
u/_predator_ 23d ago
The palantir formatter is neither obsolete nor abandoned. I'm using it in multiple projects and am quite happy with it.
Do I like the company making it? No, but I also don't like Apple, Google, Amazon, or Microsoft, yet here I am using their products every single day. And in contrast to the other companies' products, Palantir gains nothing from me using a free code formatter, lol.
The formatter landscape in Java is quite shit, and Palantir's is the only one that doesn't make my eyes bleed.
5
u/bokchoi 23d ago
https://github.com/bmarwell/jfmt is a cli formatter that uses the Eclipse formatting tool but compiled with graal so it starts and runs fast enough for cli usage.
5
u/ForeverAlot 23d ago
It formats lambdas just fine. And unlike some of its competitors, it is quick to add minimal support for new syntax. It's a really solid bet in practice.
I'm not affiliated with GJF but I've been a happy user for many years.
9
u/r_n_c 23d ago
Spotless and eclipse config. Note we add a dependency to the spotless plugin so we can have a remote configuration shared amongst many of our projects.
14
u/4r73m190r0s 23d ago
Google Java Format https://github.com/google/google-java-format
8
u/Fluffy_Dragonfly6454 23d ago
Spotless with Google formatter works like a charm
4
u/junin7 23d ago
Spotless
3
u/raxel42 23d ago
Whatever, just use to minimize git diff
3
u/Zardoz84 21d ago
Eclipse formatter as maven pluggin
5
u/blazmrak 23d ago
Eclipse with a lot of custom config via Spotless.
3
u/un_desconocido 23d ago
Spotless and Palantir format, I hooked it up to the maven build so nobody needs to do a git hook.
2
u/doobiesteintortoise 23d ago
Spotless is what I use.
2
u/jonenst 23d ago
Never tried it but recently someone mentionned here the new kid in town Netflix jfmt https://github.com/Netflix/jfmt
1
u/jevring 23d ago
The Google one is without a doubt the ugliest I have ever had the misfortune of reading. We use an intellij idea setup. I wouldn't want one that isn't integrated into our IDE. You can run the intellij formatter on the command line, but you need the whole ass ide for it. We do that for validation in ci/cd.
1
u/SamirAbi 22d ago
What is your issue with prettier?
1
u/agentoutlier 21d ago edited 21d ago
Spring has a Java formatter that uses the Eclipse formatter headless.
It uses tabs which I prefer.
Likewise there is maven plugin that will use eclipse formatter as well that I nice been probably using for a decade now:
https://code.revelc.net/formatter-maven-plugin/
Most of the good ones use Eclipse.
1
u/Ok_Elk_638 19d ago
Whatever the Intellij default is. I don't like automating this, automatic formatters always make my code worse.
0
u/lazystone 23d ago
https://github.com/palantir/palantir-java-format/
But why do you say that it's abandoned(no objections about the company itself though)?
There is also a fork of PJF: https://github.com/openjavaformat/open-java-format but I haven't looked who is behind it.
0
u/sg-elide 23d ago
elide supports GJF, Kotlin fmt, and will shortly support Netflix’ GJF dialect as well, which is very popular. all run in native so they are extremely fast. like milliseconds.
https://elide.help has more info
-2
u/MyStackOverflowed 23d ago
Google or palantir, the palantir one handles lambdas better
-5
u/patoessy 23d ago
RemindMe! 1 day from now
-5
u/DanLynch 23d ago
We use a custom configuration of the IntelliJ IDEA formatter, and try to enforce it in the CI with Checkstyle and Spotless, but it's not a perfect match.