palantir / palantir-java-format

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

Wrapping enhancements for records #834

Open JamesChenX opened 1 year ago

JamesChenX commented 1 year ago

What happened?

Original:

public record ExtensionDTO(
        String extensionClass,
        boolean started,
        boolean running,
        List<String> extensionPointClasses
) implements ControllerDTO {
}

palantir-java-format output:

public record ExtensionDTO(String extensionClass, boolean started, boolean running, List<String> extensionPointClasses)
        implements ControllerDTO {}

What did you want to happen?

The original format is more readable for humans, so I suggest there can be some enhancements:

  1. Place each record component in a new line no matter how many components there are.
  2. Place the parent class or interface in a new line.

These enhancements can make the code easier for humans to read.

iamdanfox commented 1 year ago

I'm quite sympathetic to making some kind of change here - in my mind the parameters to a record constructor seem quite analogous to the fields in a regular java class, and we already lay out fields on one per line.

I wonder if there are ever cases where it's desirable to lay them out in one line, e.g.:

record Point(int x, int y) {}

Or if we would want to always use the 'one parameter per line' style, with the trailing paren either attached or on a newline:

record Point(
    int x,
    int y) {}

// or with the trailing paren on a newline
record Point(
    int x,
    int y
) {}