palantir / palantir/palantir-java-format

Unlucky formatting for array literals at just above line length

Open
#867 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?

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
    };

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

Start with the array-literal examples and the line-length boundary described in the issue, then trace the formatter behavior for Java array literals around the closing brace. Done means the one-character-short case is formatted like the one-character-long example, with the opening and closing braces on separate lines.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.