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

org.openrewrite.yaml.MergeYaml is not respecting the current indentation of the list #5083

Open
johnsterken opened this issue Feb 21, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@johnsterken
Copy link

When merging into an existing list with no indentation, the modified entry will be indented, causing the new list to be invalid

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v8.47.1
  • Maven plugin v6.2.0

What is the smallest, simplest way to reproduce the problem?

I wrote a unit test to reproduce the issue

class MergeYamlTest implements RewriteTest {
    ...
    @Test
    void mergeListRespectIndentation() {
        rewriteRun(spec ->
            spec.recipe(new MergeYaml(
              "$",
              //language=yaml
              """
                widget:
                  list:
                  - item 2
                """,
              false,
              null,
              null,
              null,
              null
            )),
          yaml(
            """
              widget:
                list:
                - item 1
              """,
            """
              widget:
                list:
                - item 1
                - item 2
              """
          )
        );
    }
    ...
}

What did you expect to see?

 widget:
   list:
   - item 1
   - item 2

What did you see instead?

widget:
    list:
    - item 1
      - item 2
@johnsterken johnsterken added the bug Something isn't working label Feb 21, 2025
@timtebeek
Copy link
Contributor

hi John; indeed looks like we're not handling appending to non-indented list items correctly. Thanks for the runnable example!
The suggested usage for that recipe is slightly different, but even then I'm seeing similar issues with indentation on item 2.

@Test
void mergeListRespectIndentation() {
    rewriteRun(spec ->
        spec.recipe(new MergeYaml(
          "$.widget.list",
          //language=yaml
          """
            - item 2
            """,
          false,
          null,
          null,
          null,
          null
        )),
      yaml(
        """
          widget:
            list:
            - item 1
          """,
        """
          widget:
            list:
            - item 1
            - item 2
          """ // in reality item 2 is shifted to the right by two spaces :/
      )
    );
}

@timtebeek timtebeek moved this to Backlog in OpenRewrite Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants