chainguard-dev / yam

A sweet little formatter for YAML
Apache License 2.0
19 stars 9 forks source link

YAM Misformatting #20

Closed amouat closed 1 year ago

amouat commented 1 year ago

I'm working on vault.yaml and it had the following:

...
      install -m755 -d "${{targets.destdir}}/var/log/vault"

  - uses: strip

    # Apparently caps have to be set after strip!
  - runs: setcap cap_ipc_lock=+ep "${{targets.destdir}}/usr/bin/vault"
...

YAM formatted this as:

      install -m755 -d "${{targets.destdir}}/var/log/vault"

  - uses
    # Apparently caps have to be set after strip!: strip

  - runs: setcap cap_ipc_lock=+ep "${{targets.destdir}}/usr/bin/vault"

Which breaks things :/

luhring commented 1 year ago

Yeah, there's a few edge cases in the YAML library like this, e.g. https://github.com/go-yaml/yaml/issues/587 😞

Part of the problem here too is that it looks like your comment is indented one time too many, which signals your intent as wanting the comment to be associated with the content of the list item above (i.e. uses: strip).

But I'm guessing you meant for it to be a comment for the below list item itself:

...
      install -m755 -d "${{targets.destdir}}/var/log/vault"

  - uses: strip

  # Apparently caps have to be set after strip!
  - runs: setcap cap_ipc_lock=+ep "${{targets.destdir}}/usr/bin/vault"
...
amouat commented 1 year ago

Oh, ok. There's no easy fix if it's upstream. Just close this I guess.

Maybe we can think about outputting what changes it made so it's easier to catch things like this (I know there's a lint mode you can run first).