palantir / palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Apache License 2.0
403 stars 43 forks source link

Unnecessary line breaks and missed (maybe?) line breaks #1077

Open Ledmington opened 2 months ago

Ledmington commented 2 months ago

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.