Skip to content

MergeYaml edge case: keeps comment at the end of the doc after appending an entry #5135

@BoykoAlex

Description

@BoykoAlex

See the test below:

    @Test
    void insertInSequenceEntriesWithDeepSearchWithComment_1() {
        rewriteRun(
          spec -> spec.recipe(new MergeYaml(
            "$..containers",
            "imagePullPolicy: Always",
            true,
            null,
            null,
            null,
            null
          )),
          yaml(
            """
              kind: Pod
              spec:
                containers:
                  - name: <container name>  # comment
              """,
            """
              kind: Pod
              spec:
                containers:
                  - name: <container name>  # comment
                    imagePullPolicy: Always
              """
          )
        );
    }

This fails because # comment is in DocumentEnd node rather than the yaml block. Not sure what to propose... I'd probably try to keep the inline comment as part of the entry... Or perhaps have a special case for the comment at the end of the document if this would be a less intrusive fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions