palantir / palantir/palantir-java-format

Unnecessary line breaks and missed (maybe?) line breaks

Open
#1,077 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
907
Forks
101
Avg merge
1d 3h
Merged PRs (30d)
19

Description

What happened?

Hello everyone, I am using palantir 2.43.0 in a pretty large codebase through the spotless gradle plugin 6.25.0 and with gradle 8.7. Today I came around this:

private String toString(final String indent) {
    return indent
            + name
            + (parameters.isEmpty()
                    ? ""
                    : "\n" + parameters.stream().map(s -> indent + s).collect(Collectors.joining("\n")))
            + (sons.isEmpty()
                    ? ""
                    : "\n"
                            + sons.stream()
                                    .map(s -> s.toString(indent + "  "))
                                    .collect(Collectors.joining("\n")));
}

What did you want to happen?

Maybe something more like this, to avoid unnecessary line breaks.

private String toString(final String indent) {
    return indent
            + name
            + (parameters.isEmpty()
                    ? ""
                    : "\n" + parameters.stream()
                            .map(s -> indent + s)
                            .collect(Collectors.joining("\n")))
            + (sons.isEmpty()
                    ? ""
                    : "\n" + sons.stream()
                                    .map(s -> s.toString(indent + "  "))
                                    .collect(Collectors.joining("\n")));
}

I understand that it is a bit specific but I want to understand if it is an error on my side caused by ignorance and misconfiguration or if it is something that palantir can do.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the formatting of the supplied toString method with palantir 2.43.0 through the Spotless Gradle plugin 6.25.0 on Gradle 8.7, then compare the actual output with the requested output. Trace the formatter behavior responsible for the lambda and stream line breaks; done when the behavior is explained or the output matches the example without an incorrect configuration change.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.