palantir / palantir/palantir-java-format
Comment after code is not correctly indented when wrapped to the next line
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 907
- Forks
- 101
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Description
What happened?
This behaviour is observed when using spotless-plugin-gradle:6.25.0. It is also observed for the develop branch (as of 17 October 2024) in this repo, when trying it as input in a unit test (FormatterTest). It occurs for style 'palantir':
This input
class ClassB extends ClassA {
@Test
void shouldDoThisAndThat() {
instance.shouldDoSomething(Set.of(
"abcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijk", // prio (yet to go live)
"abcdefghijkabcdefghijkabcdefghijkabjkghijkabcdefghij", // prio low, not exposed yet only for manual use
"abcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkghijkabcdefghij" // prio low, not exposed yet only for manual use
));
}
}
results in the following formatted output. The second and third line of the comment are not indented correctly:
class ClassB extends ClassA {
@Test
void shouldDoThisAndThat() {
instance.shouldDoSomething(Set.of(
"abcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijk", // prio
// (yet to
// go live)
"abcdefghijkabcdefghijkabcdefghijkabjkghijkabcdefghij", // prio low, not exposed yet only
// for manual use
"abcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkghijkabcdefghij" // prio low, not exposed yet only for manual use
));
}
}
What did you want to happen?
After the line wrap, the comment should start in the same column as the comment in the first line.
This is how the indentation should look like:
class ClassB extends ClassA {
@Test
void shouldDoThisAndThat() {
instance.shouldDoSomething(Set.of(
"abcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijk", // prio
// (yet to
// go live)
"abcdefghijkabcdefghijkabcdefghijkabjkghijkabcdefghij" // prio low, not exposed yet only for
// manual use
));
...
}
}
Interestingly, it works correctly if I remove the last long line:
"abcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkghijkabcdefghij" // prio low, not exposed yet only for manual use:
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 with the FormatterTest unit test using the reported input and the palantir style, then trace the formatter code responsible for wrapping trailing comments. Reproduce the incorrect indentation and add coverage for the shown cases; done means wrapped comment lines begin in the same column as the original comment.
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
- 48/100