Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excess indentation with method-receiving text blocks #1081

Closed
Stephan202 opened this issue Mar 8, 2024 · 2 comments
Closed

Excess indentation with method-receiving text blocks #1081

Stephan202 opened this issue Mar 8, 2024 · 2 comments

Comments

@Stephan202
Copy link
Contributor

Stephan202 commented Mar 8, 2024

The new fmt-maven-plugin release comes with an upgrade from GJF 1.19.2 to GJF 1.21.0. With this upgrade it appears that text blocks inside lambda expressions that are the receiver of a method are indented too far to the right. See PicnicSupermarket/error-prone-support@a2196ee (#1069) for an example. This is what that code would look like if the text block contents are shifted to the right to match the new position of the text block start marker:

unexpectedMatchesByLineNumber.entries().stream()
    .map(
        e ->
                """
                Rule `%s` matches on line %s, while it should match in a method named \
                `test%s`."""
                .formatted(e.getValue(), e.getKey(), e.getValue()))

I.e.: an amount of indentation that better matches AOSP rather than GOOGLE style. I assume that this is a side-effect of ce3cb59.

(Apologies for not providing a 100% stand-alone reproduction case; can do that ~this weekend if desired.)

@cushon
Copy link
Collaborator

cushon commented Mar 14, 2024

Thanks for the report, I agree this is an issue. I don't think it's specific to lambda bodies, in general if text blocks show up as the receiver of a method call they are getting a surprising continuation indent:

class T {
  {
    System.err.printf("hello %s\n", world);
        """
        hello %s
        """
        .formatted("world");
  }
}

@Stephan202
Copy link
Contributor Author

Right, makes sense! Should have played around with the example a bit more. I'll update the ticket description 👍

@Stephan202 Stephan202 changed the title Excess text block indentation inside lambda expressions Excess indentation with method-receiving text blocks Mar 15, 2024
copybara-service bot pushed a commit that referenced this issue Apr 1, 2024
… commit

Previously the formatting was adding a forced break at the beginning of text blocks, which caused issues like #1081. With the changes in the baseline CL it correctly handles the 'width' of text blocks containing newlines as infinity, instead of counting the number of characters and treating the newline as having width 1.

Fixes #1081

PiperOrigin-RevId: 620311510
copybara-service bot pushed a commit that referenced this issue Apr 1, 2024
… commit

Previously the formatting was adding a forced break at the beginning of text blocks, which caused issues like #1081. With the changes in the baseline CL it correctly handles the 'width' of text blocks containing newlines as infinity, instead of counting the number of characters and treating the newline as having width 1.

Fixes #1081

PiperOrigin-RevId: 620311510
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants