1

I am using spotless to format my java code and I am fairly happy with it. However it keeps reformatting my builders so that everything is on one line when it is within the line limits.

For example this

final var user = User.builder()
    .id(1L)
    .name("name")
    .build();

becomes this

final var user = 
    User.builder().id(1L).name("name").build();

I know that I can turn off spotless for certain snippets by using spotless:off/on, however we are using builders so extensively that this would escalate into a tedious task fairly quickly.

So is there a way to force spotless to keep line breaks for these builders?

EDIT I noticed i have the samte problem for longer assertThat statements:

assertThat(result.getContacts())
    .hasSize(2)
    .contains(newContact)
    .contains(contactToUpdate);

becomes this

assertThat(result.getContacts()).hasSize(2).contains(newContact).contains(contactToUpdate);
Zounadire
  • 1,496
  • 2
  • 18
  • 38
  • you can add empty `//` (line comments) to force line breaks - that works for basically every formatter. Still quite spammy (lot of noise) in most cases :/ – spamove Jul 28 '23 at 06:53

0 Answers0