Skip to content

Formatter wraps short calls one element per line: keep a single selector or argument on the same line #223

Closed

Description

@bertysentry

Where: metricshub-eclipse-formatter.xml (the MetricsHub Eclipse formatter profile, applied by formatter-maven-plugin 2.29.0 and checked by formatter:validate).

What happens: when a statement does not fit in 120 columns, the formatter wraps the outermost call first, puts every selector and every argument on a line of its own, and indents each level by two more tabs. A short call with a single long argument ends up spread over many lines. Example from SdrWalker.walk() (PR #222, SdrWalker.java#L149-L157):

					skipped
							.add(
									new SkippedRecord(
											recordId,
											lastRecordType,
											String
													.format(
															"Names record %04Xh as the next one, which was read already: the walk ends there",
															nextRecordId)));

skipped.add( and String.format( fit on one line each, yet the selector (.add, .format) goes to its own line and the opening of the call to yet another one.

What should happen: keep a single selector, and a single argument, on the same line as what precedes it whenever it fits, and wrap only the inner arguments that do not fit:

					skipped.add(new SkippedRecord(
							recordId,
							lastRecordType,
							String.format(
									"Names record %04Xh as the next one, which was read already: the walk ends there",
									nextRecordId)));

Rule: when there is only one method call in a chain, or only one argument, and it fits on the current line, keep it there instead of breaking the line and indenting.

Settings involved (current values):

Setting Value Effect
wrap_outer_expressions_when_nested true Wraps the outer expression (skipped.add(...)) before the nested ones, so the outer call breaks although only the inner arguments are too long
alignment_for_selector_in_method_invocation 48 (wrap all elements, each on a new line) skipped / .add( and String / .format( are split even for a single selector
alignment_for_arguments_in_method_invocation 48 A single argument (new SkippedRecord(...)) goes to a new line
alignment_for_arguments_in_allocation_expression 48 Same for new X(...)
join_wrapped_lines false Lines wrapped once are never joined back, so changing the other settings alone does not reformat existing code

A starting point to try: wrap_outer_expressions_when_nested=false, and 16 (wrap where necessary) instead of 48 for the selector alignment, and possibly for the argument alignments too. Run it over the whole code base once with join_wrapped_lines=true so that existing wraps are reflowed. Compare the result on a few typical files (SdrWalker, IpmiClient, IpmiCli, the core coders) before adopting it. These values are untested: check what Eclipse 4.x actually produces with them.

Constraints:

  • AGENTS.md says the profile is byte-identical to jawk's. Changing it here either breaks that, or must be done in both repositories (or in a shared profile) at the same time. Decide which one first.
  • The reformat touches most Java files: do it in a commit of its own, with no other change, and add that commit to .git-blame-ignore-revs so that git blame skips it.
  • Checkstyle (checkstyle.xml, also shared with jawk) must still pass on the reformatted code.

Activity

  1. bertysentry commented on Oct 20, 2026

    @bertysentry
    ContributorAuthor

    Same issue filed for jawk (jawkio/jawk#627, same profile, byte-identical) and winrm-java (MetricsHub/winrm-java#209, its own variant: selectors are already wrapped only where necessary, so only the single-argument and outer-first wrapping apply).

  2. self-assigned this
    on Oct 25, 2026
  3. added 2 commits that reference this issue on Oct 25, 2026
  4. added a commit that references this issue on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions