Skip to content

Mismatch between IntelliJ and maven formatting for string line-wraps #1451

@HoelzelJon

Description

@HoelzelJon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions