palantir / palantir-java-format

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

Unlucky formatting for array literals at just above line length #867

Open magicus opened 1 year ago

magicus commented 1 year ago

What happened?

The following formatting is produced by Palantir (we run it as a plugin to Spotless), version 2.28.0:

    private static final int[] ACCESSORY_SLOTS = {RING_1_SLOT_NUM, RING_2_SLOT_NUM, BRACELET_SLOT_NUM, NECKLACE_SLOT_NUM
    };

It does not look pretty. :-(

As soon as you add one additional character, it looks much better:

    private static final int[] ACCESSORY_SLOTS = {
        RING_1_SLOT_NUM, RING_2_SLOT_NUM, BRACELET_SLOT_NUM, NECKLACE_SLOT_NUM2
    };

or if you remove two characters:

    private static final int[] ACCESSORY_SLOTS = {RING_1_SLOT_NUM, RING_2_SLOT_NUM, BRACELET_SLOT_NUM, NECKLACE_SLOT_N};

(though I personally disagree with the lack of space surrounding the brace in this case)

What did you want to happen?

I would have expected it to look like in the one character longer example, since the closing brace did not fit on the same line as the opening brace:

    private static final int[] ACCESSORY_SLOTS = {
        RING_1_SLOT_NUM, RING_2_SLOT_NUM, BRACELET_SLOT_NUM, NECKLACE_SLOT_NUM
    };