palantir / palantir/palantir-java-format

IntelliJ plugin splits strings across lines when maven version doesn't

Open
#1,452 2 comments 3 reactions 0 assignees View on GitHub

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 example =
                "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah";
    }
}

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 format the file using the IntelliJ plugin with a version >= 2.78.0, the string is forcibly split out to a second line:

class Test {
    public static void main(String[] args) {
        String example =
                "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah"
                        + " blah";
    }
}

It seems surprising to me that formatting the file would have different results when triggered via maven versus via the IntelliJ plugin. In principle, I'm not at all opposed to forcibly wrapping overly-long single-line strings, but it seems best to have consistent behavior between the IntelliJ plugin and the maven logic.

For example, this is troublesome if a project primarily uses the maven plugin to ensure formatting consistency, but my IntelliJ (with plugin version >= 2.78.0) is configured to automatically apply formatting to files I edit. In this scenario, any files I touch that have strings extending past column=120 are automatically reformatted, even if these strings are unrelated to the parts of the file that I'm editing. This is then likely to pollute commits with unrelated formatting changes.

This issue is made worse by the existence of #1451 , because some of the lines that the IntelliJ plugin is now choosing to split will immediately fail to match the maven-plugin's formatting expectations.

I believe this was introduced in #1419 , since that is the only non-"excavator" change between versions 2.77.0 and 2.78.0.

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 pom.xml configuration and the minimal Java file in the report, then compare formatting through the Maven plugin and IntelliJ plugin for versions 2.77.0 and 2.78.0. Review the change associated with #1419 and check the interaction with #1451. Done means both entry points produce consistent output for the reported string.

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
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.