palantir / palantir/palantir-java-format
Make Map.of() and ImmutableMap.of() more readable
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 907
- Forks
- 101
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Description
Currently, the formatter will format Map.of() as either:
// Shorter list
Map<String, String> map1 = Map.of("key1", value1, "key2", value2, "key3", value3);
// Longer list
Map<String, String> map2 = Map.of(
"key1",
longerValue1,
"key2",
longerValue2,
"key3",
longerValue3,
"key4",
longerValue4,
"key5",
longerValue5,
"key6",
longerValue6);
These are not very readable, especially when the keys are not visually distinguishable from values.
It would be much more readable if it would format them like this instead:
// Shorter list
Map<String, String> map1 = Map.of(
"key1", value1,
"key2", value2,
"key3", value3);
// Longer list
Map<String, String> map2 = Map.of(
"key1", longerValue1,
"key2", longerValue2,
"key3", longerValue3,
"key4", longerValue4,
"key5", longerValue5,
"key6", longerValue6);
You may need to special case Map.of() and ImmutableMap.of(), as I don't think there is any more general rule.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the formatter logic that handles Map.of() and ImmutableMap.of(); no source files or tests are named in the issue. Add regression coverage for the shorter and longer examples, then verify that each key-value pair is kept together on its own line while existing formatting remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100