Skip to content

Fix XML attribute continuation indentation - #8659

Merged
jkschneider merged 2 commits into
openrewrite:mainfrom
Wanbinyu:fix/3648-xml-autoformat-indentation
Aug 27, 2026
Merged

jkschneider merged 2 commits into
openrewrite:mainfrom
Wanbinyu:fix/3648-xml-autoformat-indentation

Conversation

@Wanbinyu

@Wanbinyu Wanbinyu commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What's changed?

  • Detect XML attribute continuation indentation relative to the parent tag instead of as an absolute column.
  • Apply normal tag-depth indentation plus one continuation indent, preventing indentation from multiplying across recipe cycles.
  • Add regression coverage for a single continuation sample, nested attributes, and explicitly styled indentation.

What's your motivation?

AutoFormat could repeatedly expand the leading whitespace of continued XML attributes. The detected continuation indent included the parent tag's existing indentation, while the formatter multiplied that absolute value by the tag depth on every cycle.

Anything in particular you'd like reviewers to focus on?

Please review the relative indentation calculation in Autodetect and the handling of attribute continuations in TabsAndIndentsVisitor.

Have you considered any alternatives or workarounds?

Changing only TabsAndIndentsVisitor would stop the multiplicative growth, but autodetection would still treat the absolute column as the continuation width and move nested attributes on subsequent cycles. The change therefore keeps detection and application consistent.

Any additional context

Validated after merging the latest main with:

  • ./gradlew :rewrite-xml:check (includes the complete rewrite-xml test suite, license checks, and recipe CSV validation)
  • ./gradlew :rewrite-docker:test --tests org.openrewrite.docker.search.FindEndOfLifeImagesTest.mixedEolAndCurrent
  • git diff --check

The initial CI failure was limited to the unrelated rewrite-docker end-of-life fixture. It reproduced on the then-current upstream main and was fixed upstream by #8661; the previously failing test now passes after syncing this branch with main. No Docker code or tests are changed by this PR.

Tests were run with configuration-on-demand and a local Java 8 toolchain on Windows.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've run the complete rewrite-xml test and check tasks
  • I've formatted only the lines I changed, without reformatting unrelated code

@Wanbinyu
Wanbinyu marked this pull request as ready for review August 27, 2026 02:58
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Aug 27, 2026
@jkschneider
jkschneider merged commit 4374fb9 into openrewrite:main Aug 27, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

XML Autoformat indentation issue

3 participants