Skip to content

feat: configure Eclipse formatter for Spotless#571

Open
swetasamasti2310 wants to merge 2 commits into
docling-project:mainfrom
swetasamasti2310:feat/configure-eclipse-formatter
Open

feat: configure Eclipse formatter for Spotless#571
swetasamasti2310 wants to merge 2 commits into
docling-project:mainfrom
swetasamasti2310:feat/configure-eclipse-formatter

Conversation

@swetasamasti2310

Copy link
Copy Markdown

Title: feat: configure Eclipse formatter for Spotless
Description:

Changes

  • Updated Eclipse formatter XML to match .editorconfig settings
  • Changed indentation from 4 to 2 spaces
  • Changed line length from 120 to 180 characters
  • Enabled new lines before else/catch/finally
  • Updated Spotless config to use Eclipse formatter

Testing

  • Ran ./gradlew spotlessApply - formatting works correctly
  • Ran ./gradlew spotlessCheck - all checks pass
  • Verified 2-space indentation is applied

Resolves #378

@swetasamasti2310 swetasamasti2310 force-pushed the feat/configure-eclipse-formatter branch from 1547ca1 to 2783a95 Compare June 29, 2026 04:11
@edeandrea edeandrea force-pushed the feat/configure-eclipse-formatter branch from 2783a95 to 2561a3a Compare July 7, 2026 13:37
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

:java_duke: JaCoCo coverage report

Overall Project 46.12% 🔴

There is no coverage information present for the Files changed

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
TestsPassed ✅SkippedFailed
Gradle Test Results (all modules & JDKs)1520 ran1520 passed0 skipped0 failed
TestResult
No test annotations available

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@edeandrea edeandrea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @swetasamasti2310 !

See specific comments below.

Note that just running spotlessCheck or spotlessApply won't do anything unless there is a file which has changed. Spotless only looks at files that have changed status, so if you want to see what the rules are doing then you have to modify some files (add a blank line somewhere in a file will work).

One general comment I found when I tried this out. When I changed a file and re-ran spotlessApply I noticed that some enums got messed up:

Before

public enum ContentLayer {
    @JsonProperty("body") BODY,
    @JsonProperty("furniture") FURNITURE,
    @JsonProperty("background") BACKGROUND,
    @JsonProperty("invisible") INVISIBLE,
    @JsonProperty("notes") NOTES
  }

  public enum GroupLabel {
    @JsonProperty("unspecified") UNSPECIFIED,
    @JsonProperty("list") LIST,
    @JsonProperty("ordered_list") ORDERED_LIST,
    @JsonProperty("chapter") CHAPTER,
    @JsonProperty("section") SECTION,
    @JsonProperty("sheet") SHEET,
    @JsonProperty("slide") SLIDE,
    @JsonProperty("form_area") FORM_AREA,
    @JsonProperty("key_value_area") KEY_VALUE_AREA,
    @JsonProperty("comment_section") COMMENT_SECTION,
    @JsonProperty("inline") INLINE,
    @JsonProperty("picture_area") PICTURE_AREA
  }

After

  public enum ContentLayer {
    @JsonProperty("body") BODY, @JsonProperty("furniture") FURNITURE, @JsonProperty("background") BACKGROUND, @JsonProperty("invisible") INVISIBLE, @JsonProperty("notes") NOTES
  }

  public enum GroupLabel {
    @JsonProperty("unspecified") UNSPECIFIED, @JsonProperty("list") LIST, @JsonProperty("ordered_list") ORDERED_LIST, @JsonProperty("chapter") CHAPTER, @JsonProperty("section") SECTION, @JsonProperty("sheet") SHEET, @JsonProperty("slide") SLIDE, @JsonProperty("form_area") FORM_AREA, @JsonProperty("key_value_area") KEY_VALUE_AREA, @JsonProperty("comment_section") COMMENT_SECTION, @JsonProperty("inline") INLINE, @JsonProperty("picture_area") PICTURE_AREA
  }

Is there a way to ensure that enums constants stay on individual lines?

I also noticed that when I have chained items, like this:

request.headers()
          .map()
          .entrySet()
          .stream()
          .map(this::maskSensitiveHeaderValues)
          .forEach(entry -> stringBuilder.append("  %s: %s\n".formatted(entry.getKey(), String.join(", ", entry.getValue())))
      );

after re-running spotlessApply they get shrunk to a single line

request.headers().map().entrySet().stream().map(this::maskSensitiveHeaderValues).forEach(entry -> stringBuilder.append("  %s: %s\n".formatted(entry.getKey(), String.join(", ", entry.getValue())))
      );

Is there a way to turn that off?

Comment thread .spotless/eclipse-java-formatter.xml Outdated
@swetasamasti2310 swetasamasti2310 force-pushed the feat/configure-eclipse-formatter branch from 2561a3a to 734c451 Compare July 9, 2026 17:08
@swetasamasti2310

Copy link
Copy Markdown
Author

Thanks for this @swetasamasti2310 !

See specific comments below.

Note that just running spotlessCheck or spotlessApply won't do anything unless there is a file which has changed. Spotless only looks at files that have changed status, so if you want to see what the rules are doing then you have to modify some files (add a blank line somewhere in a file will work).

One general comment I found when I tried this out. When I changed a file and re-ran spotlessApply I noticed that some enums got messed up:

Before

public enum ContentLayer {
    @JsonProperty("body") BODY,
    @JsonProperty("furniture") FURNITURE,
    @JsonProperty("background") BACKGROUND,
    @JsonProperty("invisible") INVISIBLE,
    @JsonProperty("notes") NOTES
  }

  public enum GroupLabel {
    @JsonProperty("unspecified") UNSPECIFIED,
    @JsonProperty("list") LIST,
    @JsonProperty("ordered_list") ORDERED_LIST,
    @JsonProperty("chapter") CHAPTER,
    @JsonProperty("section") SECTION,
    @JsonProperty("sheet") SHEET,
    @JsonProperty("slide") SLIDE,
    @JsonProperty("form_area") FORM_AREA,
    @JsonProperty("key_value_area") KEY_VALUE_AREA,
    @JsonProperty("comment_section") COMMENT_SECTION,
    @JsonProperty("inline") INLINE,
    @JsonProperty("picture_area") PICTURE_AREA
  }

After

  public enum ContentLayer {
    @JsonProperty("body") BODY, @JsonProperty("furniture") FURNITURE, @JsonProperty("background") BACKGROUND, @JsonProperty("invisible") INVISIBLE, @JsonProperty("notes") NOTES
  }

  public enum GroupLabel {
    @JsonProperty("unspecified") UNSPECIFIED, @JsonProperty("list") LIST, @JsonProperty("ordered_list") ORDERED_LIST, @JsonProperty("chapter") CHAPTER, @JsonProperty("section") SECTION, @JsonProperty("sheet") SHEET, @JsonProperty("slide") SLIDE, @JsonProperty("form_area") FORM_AREA, @JsonProperty("key_value_area") KEY_VALUE_AREA, @JsonProperty("comment_section") COMMENT_SECTION, @JsonProperty("inline") INLINE, @JsonProperty("picture_area") PICTURE_AREA
  }

Is there a way to ensure that enums constants stay on individual lines?

I also noticed that when I have chained items, like this:

request.headers()
          .map()
          .entrySet()
          .stream()
          .map(this::maskSensitiveHeaderValues)
          .forEach(entry -> stringBuilder.append("  %s: %s\n".formatted(entry.getKey(), String.join(", ", entry.getValue())))
      );

after re-running spotlessApply they get shrunk to a single line

request.headers().map().entrySet().stream().map(this::maskSensitiveHeaderValues).forEach(entry -> stringBuilder.append("  %s: %s\n".formatted(entry.getKey(), String.join(", ", entry.getValue())))
      );

Is there a way to turn that off?

@edeandrea Earlier I tested with code change only but I didn't change for all the settings. Now I have done changes for these also i.e. Enum and chained items also. In addition to this settings. I have also changed other settings trying to make as similar as possible to the settings given in .editorConfig. Tested for each scenario with code changes.

- Updated Eclipse formatter XML to match .editorconfig
- Changed indentation from 4 to 2 spaces
- Changed line length from 120 to 180 characters
- Enabled new lines before else/catch/finally

Resolves docling-project#378

Signed-off-by: swetasamasti2310 <swetagupta2310@gmail.com>
- Added eclipse().configFile() to use Eclipse formatter XML
- Added removeUnusedImports() to clean up imports
- Added trimTrailingWhitespace() for whitespace cleanup
- Added endWithNewline() to ensure files end with newline

Signed-off-by: swetasamasti2310 <swetagupta2310@gmail.com>
@edeandrea edeandrea force-pushed the feat/configure-eclipse-formatter branch from 734c451 to 17fc4e7 Compare July 10, 2026 19:56
@github-actions

Copy link
Copy Markdown

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@edeandrea

Copy link
Copy Markdown
Contributor

Thanks @swetasamasti2310

This may not be the behavior of the current .editorConfig, but is there a way to tell it that something like this

@JsonProperty("children")
@JsonSetter(
     nulls = Nulls.AS_EMPTY)
@lombok.Singular("child")
private List<RefItem> children;

Should be this?

@JsonProperty("children")
@JsonSetter(nulls = Nulls.AS_EMPTY)
@lombok.Singular("child")
private List<RefItem> children;

The carriage return in the annotation parameter - there shouldn't be a preceding carriage return.

Similar with try & catch blocks:

try (
    InputStream is = (InputStream) body) {
  body = new String(is.readAllBytes(), StandardCharsets.UTF_8);
}
catch (
    IOException
    | InterruptedException e) {
  throw new DoclingServeClientException(e);
}

should be

try (InputStream is = (InputStream) body) {
  body = new String(is.readAllBytes(), StandardCharsets.UTF_8);
}
catch (IOException | InterruptedException e) {
  throw new DoclingServeClientException(e);
}

During a cast, there should also be an extra space

return (T) StreamResponse
          .body((InputStream)body)

should be

return (T) StreamResponse
          .body((InputStream) body)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create code formatting rules

2 participants