Skip to content

Make long-string wrapping idempotent (fixes #935) - #1463

Open
tanvir-ux wants to merge 1 commit into
google:masterfrom
tanvir-ux:fix-935-string-wrap-idempotent
Open

tanvir-ux wants to merge 1 commit into
google:masterfrom
tanvir-ux:fix-935-string-wrap-idempotent

Conversation

@tanvir-ux

Copy link
Copy Markdown

Summary

Fixes #935.

StringWrapper builds wrapped string concatenations with a continuation indent based on the string literal's start column (startColumn + 4). When the literal is prefixed (for example after return ), that disagrees with the pretty-printer, which breaks + relative to the statement. The wrap pass then returned that over-indented text without a final format, so a second CLI/formatSource run rewrote the file.

After applying wrap replacements (and the existing AST sanity check), run formatter.formatSource once more so the output matches what a subsequent format pass would produce.

Test plan

  • mvn -pl core -Dtest=StringWrapperTest,StringWrapperIntegrationTest test — 80/80 (includes new wrapThenFormatIsIdempotentForPrefixedString)
  • mvn -pl core -Dtest=FormatterIntegrationTest test — 1045/1045
  • Manual CLI: format the String wrapping is not idempotent #935 comment repro (return "Very, very, … need to be split") twice with the all-deps jar; second pass is a no-op
  • Manual CLI: original switch-expression example from String wrapping is not idempotent #935 also stable

Notes

Google CLA already signed for this account (cla/google green on recent google/auto PRs).

StringWrapper.applyReplacements chooses '+' continuation indents from
the string literal's start column. When the literal is prefixed (e.g.
after `return`), that indent disagrees with the pretty-printer, so a
second format pass rewrote the file (issue google#935).

Format once more after applying wrap replacements so the output is
stable under subsequent formatSource / CLI runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String wrapping is not idempotent

1 participant