palantir / palantir/palantir-java-format
Palantir formatter behaves weirdly with switch assignments
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 907
- Forks
- 101
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Description
What happened?
How code was written:
float renderX, renderY;
renderX = switch (horizontalAlignment) {
case Left -> x;
case Center -> x - font.width(text) / 2f;
case Right -> x - font.width(text);
};
renderY = switch (verticalAlignment) {
case Top -> y;
case Middle -> y - font.lineHeight / 2f;
case Bottom -> y - font.lineHeight;
};
After Palantir (2.26.0) format:
float renderX, renderY;
renderX = switch (horizontalAlignment) {
case Left -> x;
case Center -> x - font.width(text) / 2f;
case Right -> x - font.width(text);};
renderY = switch (verticalAlignment) {
case Top -> y;
case Middle -> y - font.lineHeight / 2f;
case Bottom -> y - font.lineHeight;};
}; is in a weird place now.
What did you want to happen?
My suggestion is that }; should be auto-formatted to be in the next line after the last case.
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 running Palantir Java Format 2.26.0 against the switch-assignment example in the issue and inspect the formatter path handling switch expressions. Find the existing formatter regression tests, then add coverage showing that the closing }; follows the final case and verify the corrected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100