Stop splitting a chained invocation that would fit on one line - #153
Merged
Merged
Conversation
The formatter put every selector in a chain on its own line whether or not the
whole thing fitted, so ordinary stream and builder code was several times taller
than it needed to be:
this.entityTypes.addAll(entity.getEntityTypes()
.stream()
.map(this::adaptEntityType)
.toList());
becomes
this.entityTypes.addAll(entity.getEntityTypes().stream().map(this::adaptEntityType).toList());
Two settings, and they only work together. alignment_for_selector_in_method_invocation
was 85 - M_NEXT_PER_LINE_SPLIT plus M_INDENT_BY_ONE plus M_FORCE - and M_FORCE is
what splits regardless of fit, so it drops to 84. On its own that changes nothing,
because join_wrapped_lines was false and the Eclipse formatter then only ever adds
a wrap, never removes one already there. So that moves to true as well. lineSplit
stays at 200.
175 files, about 1,360 lines shorter. Clean verify on all three profiles.
The generator templates are unaffected, which was the thing worth checking: a raw
regeneration followed by one spotless:apply still lands exactly on the committed
sources, so the zero-diff property CLAUDE.md describes survives. The
21,000-character lines in the generated libraries are injected SVG string
literals, byte-identical before and after - a string constant cannot be wrapped.
Quality rather than just height: of 147 newly joined lines in hand-written code,
138 are 90 characters or shorter and the longest is 114, against a limit of 200.
This stays the Eclipse formatter deliberately. Re-importing the profile leaves the
IDE's Source > Format agreeing with the build, which a switch to
palantir-java-format or google-java-format would have given up - along with
reformatting every generated file and retuning the templates.
The trade-off: join_wrapped_lines now rejoins lines that were wrapped on purpose,
which is presumably why it was false. Where a hand layout matters,
// @Formatter:off and // @Formatter:on still work.
Closes #152.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #152.
Two settings, and neither works alone
M_FORCEsplits regardless of fit, so it drops to 84. On its own that changes nothing, becausejoin_wrapped_lineswasfalseand the Eclipse formatter then only ever adds a wrap, never removes one already present — so that moves to true as well.lineSplitstays at 200.That interaction is the whole reason this looked like a formatter-choice problem rather than a two-line config problem.
Measured
clean verify-Pstandard,-Phistorical,-Pbattleorderspotless:applylands exactly on the committed sourcesThat last row was the thing worth checking, and it is why this is cheap: the zero-diff property
CLAUDE.mddescribes still holds, so no template needed retuning.Quality rather than just height — of 147 newly joined lines in hand-written code, 138 are ≤90 characters and the longest is 114, against a limit of 200:
The 21,000-character lines in the generated libraries are injected SVG string literals, byte-identical before and after. A string constant cannot be wrapped, and this does not make them worse.
It stays the Eclipse formatter, deliberately
Re-import the profile and the IDE's Source → Format agrees with the build again. A switch to palantir-java-format or google-java-format would have given that up, reformatted every generated file, and needed the templates retuned — for a chain style this already achieves.
The trade-off
join_wrapped_lines = truemeans the formatter now rejoins lines that were wrapped on purpose, which is presumably why it wasfalse. Where a hand layout genuinely matters,// @formatter:off/// @formatter:onstill work.Worth reviewing the diff for any place where a deliberate layout was worth keeping — it is mechanical, so anything that reads worse is a candidate for a
@formatter:offrather than a reason to drop the change.🤖 Generated with Claude Code