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

Yamlfix generates invalid yaml if comment in a block when top level is a list #278

Open
nonell-viavi opened this issue Apr 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nonell-viavi
Copy link

nonell-viavi commented Apr 16, 2024

First of all, thank you for this fantastic tool!

Now to the issue :)

Description

When the yaml file is organized in a certain way, yamlfix generates invalid YAML as the output.

Steps to reproduce

  1. This is the smallest file that reproduces the issue:
    ---
    - a: |-
      # comment
      content
  2. Run yamlfix <file.yaml>

Current behavior

This is the resulting file, which is not valid YAML.

---
- a: |-
      # comment
    content

Desired behavior

I would expect the comment to be left as it is, not shifted right. I think yamlfix is treating the comment as a comment instead of text under the |- block.

The interesting bit is that this only manifests when the top level object is a list! (When top level is a dict, this doesn't happen).

---
a: |-
  # comment
  content

^ This is left as it is.

Environment

$ python -c "import yamlfix.version; print(yamlfix.version.version_info())"
------------------------------------------------------------------
     yamlfix: 1.16.0
     Python: 3.11.8
     Platform: Linux-4.18.0-544.el8.x86_64-x86_64-with-glibc2.28
------------------------------------------------------------------
@nonell-viavi nonell-viavi added the bug Something isn't working label Apr 16, 2024
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
None yet
Development

No branches or pull requests

1 participant