Create code formatting rules
Now that we have spotless scanning during PRs. we need to decide upon what formatting rules we want.
For now, only import ordering is turned on.
Myself & @ThomasVitale will need to take this up.
@dosu is there anything you can offer here?
I can share what I found about your current setup and some options to consider:
Current state:
- Your Spotless config only enforces import ordering right now
- You have a comprehensive
.editorconfig(1,400+ lines) with IntelliJ settings—2-space indentation, 180-char line width, no wildcard imports, etc.
Options for Spotless formatting rules:
-
Google Java Format – Opinionated, zero-config, widely adopted. Add
googleJavaFormat()to your Spotless block. -
Palantir Java Format – Based on Google's but with some differences (e.g., longer line lengths). Add
palantirJavaFormat(). -
Eclipse formatter – If you want to match your existing
.editorconfigsettings exactly, you can export Eclipse formatter XML and useeclipse().configFile(...). This gives full control but requires maintaining the config. -
Cleanthat – Spotless has
cleanthat()for applying safe code cleanups (removing unnecessary semicolons, etc.).
Since you already have detailed preferences in .editorconfig, using the Eclipse formatter approach would preserve those choices. Alternatively, adopting Google Java Format would be simpler and avoid bikeshedding—though it may require reformatting existing code (the ratchetFrom("origin/main") setting would limit this to changed files).
Would you like more details on any of these approaches?
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
@dosu i've seen using kotlin you can configure spotless to read from .editorconfig, but I couldn't figure out a way with java code to get spotless to respect what's in .editorconfig
You're right that Kotlin has native .editorconfig support in Spotless via ktlint(), but unfortunately Spotless does not have equivalent native .editorconfig support for Java formatting.
The Java formatters available in Spotless (googleJavaFormat(), eclipse(), palantirJavaFormat()) each have their own configuration mechanisms—none read .editorconfig directly.
Your main options are:
-
Eclipse formatter – Export your formatting preferences from IntelliJ (or Eclipse) as an XML file, then use
eclipse().configFile("path/to/eclipse-formatter.xml"). This is the closest to preserving your existing.editorconfigsettings, but requires maintaining a separate XML config. -
Accept an opinionated formatter – Use
googleJavaFormat()orpalantirJavaFormat()and accept their predefined styles rather than matching your.editorconfig. -
Keep the current hybrid approach – As noted in your CONTRIBUTING.md, rely on IDE enforcement of
.editorconfigand only use Spotless for import ordering (or other targeted rules).
The gap between Kotlin and Java here is essentially because ktlint was designed with .editorconfig support, while the Java formatters predate that convention.
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.