docling-java icon indicating copy to clipboard operation
docling-java copied to clipboard

Create code formatting rules

Open edeandrea opened this issue 9 months ago • 4 comments

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.

edeandrea avatar Mar 02 '26 16:03 edeandrea

@dosu is there anything you can offer here?

edeandrea avatar Mar 03 '26 14:03 edeandrea

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:

  1. Google Java Format – Opinionated, zero-config, widely adopted. Add googleJavaFormat() to your Spotless block.

  2. Palantir Java Format – Based on Google's but with some differences (e.g., longer line lengths). Add palantirJavaFormat().

  3. Eclipse formatter – If you want to match your existing .editorconfig settings exactly, you can export Eclipse formatter XML and use eclipse().configFile(...). This gives full control but requires maintaining the config.

  4. 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.

Leave Feedback Ask Dosu about docling-java Share Dosu with your team

dosubot[bot] avatar Mar 03 '26 14:03 dosubot[bot]

@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

edeandrea avatar Mar 03 '26 14:03 edeandrea

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:

  1. 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 .editorconfig settings, but requires maintaining a separate XML config.

  2. Accept an opinionated formatter – Use googleJavaFormat() or palantirJavaFormat() and accept their predefined styles rather than matching your .editorconfig.

  3. Keep the current hybrid approach – As noted in your CONTRIBUTING.md, rely on IDE enforcement of .editorconfig and 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.

Leave Feedback Learn about docling-java with Dosu Add Dosu to your team

dosubot[bot] avatar Mar 03 '26 15:03 dosubot[bot]