palantir / palantir/palantir-java-format
Mismatch between IntelliJ and maven formatting for string line-wraps
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 908
- Forks
- 101
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Description
To create a minimal example, I've created an otherwise-empty maven project, with palantir formatting configured via spotless:
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<java>
<palantirJavaFormat>
<version>2.77.0</version>
</palantirJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>
This is the java file I'm using to test. This matches the formatting applied by palantir formatter v2.77.0 (when invoked by either IntelliJ or Maven).
class Test {
public static void main(String[] args) {
String s =
"This string gets wrapped poorly because the end of the second line falls within columns 121 and 123!"
+ " We expect that this second line will be indented 8 spaces beyond the indentation of the start"
+ " of the string, but it's sometimes getting indented 4 spaces instead!";
}
}
If I change the palantirJavaFormat -> version in the pom.xml to 2.78.0 and re-run mvn spotless:apply, there are still no formatting changes made to the java file.
However, if I upgrade my IntelliJ palantir plugin to version 2.78.0 (or higher), then this gets reformatted as follows:
class Test {
public static void main(String[] args) {
String s =
"This string gets wrapped poorly because the end of the second line falls within columns 121 and 123!"
+ " We expect that this second line will be indented 8 spaces beyond the indentation of the start"
+ " of the string, but it's sometimes getting indented 4 spaces instead!";
}
}
The difference here is that the subsequent lines of the string are indented 4 spaces instead of 8 beyond the indentation of the initial line of the string. From what I can tell, this applies when the final character of a subsequent line of a multi-line string would land on a column between 121 and 123 (inclusive) if the subsequent lines were indented 8 spaces.
It is troublesome that this is formatted differently in IntelliJ versus the maven spotless plugin. With this bug present, applying formatting within IntelliJ can lead to failures to conform to expected formatting according to the maven spotless plugin.
I would guess this was introduced in #1419 , since that is the only non-"excavator" change between versions 2.77.0 and 2.78.0.
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
Reproduce the example with palantir-java-format 2.77.0 and 2.78.0 through IntelliJ and the Maven Spotless configuration, then compare the formatting behavior around the 120-character limit. Read the change referenced in #1419 and verify that the Maven and IntelliJ paths produce the same indentation for the supplied Java file.
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
- 45/100