Skip to content

Preserve inline comments when moving YAML properties and relocate doc… - #8701

Open
KamilPatora wants to merge 5 commits into
openrewrite:mainfrom
KamilPatora:kamil/refactor-yaml-merge-visitor
Open

Preserve inline comments when moving YAML properties and relocate doc…#8701
KamilPatora wants to merge 5 commits into
openrewrite:mainfrom
KamilPatora:kamil/refactor-yaml-merge-visitor

Conversation

@KamilPatora

@KamilPatora KamilPatora commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

What's changed?

-Preserve inline comments stored in Yaml.Document.End.prefix when ChangePropertyKey moves another property after their original owner.
-Add a focused, package-private YamlDocumentEndCommentRelocator.
-Relocate a comment only when:its original owner still exists,it gains an immediate successor,and the same comment is still present in the document-end prefix.
-Preserve CRLF line endings, standalone comments, and YAML document separators.
-Add regression coverage for deeply nested properties, moved final properties, multi-document YAML, CRLF, and standalone comments.

What's your motivation?

When ChangePropertyKey moved a non-final property, an inline comment belonging to an unchanged final property remained in the document-end prefix. After the moved property was inserted, the comment was rendered as though it belonged to that property.

The fix tracks the original final entry by its ID and moves the comment to the prefix of its new immediate successor. If the original owner no longer exists or remains the final entry, the document-end comment is left unchanged.

spring:
data:
mongodb:
uri: "test"
servlet:
multipart:
max-request-size: 162529280 #155MB

spring:
servlet:
multipart:
max-request-size: 162529280
mongodb:
uri: "test" #155MB

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

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant