chainguard-dev / yam

A sweet little formatter for YAML
Apache License 2.0
20 stars 10 forks source link

feature: list formatting #62

Closed wlynch closed 3 months ago

wlynch commented 3 months ago

For some fields (like update.exclude comment) we may include list for details comments e.g.

1. ...
2. ...
3. ...

or

- ...
- ...
- ...

Currently yam doesn't know how to handle these, because it treats them as a gap-less multiline string, and ends up collapsing these into a single line. Really we want to treat this more like markdown and preserve this whitespace.

luhring commented 3 months ago

Hey there — I'm not quite following the scenario yet... do you have an example file on hand where we could reproduce what you're seeing? There are a few known bugs with the underlying go-yaml library regarding comment handling, so curious if it's one of those, or if it's something we have more control over in yam itself 🤞

wlynch commented 3 months ago

Sure! So this config:

update:
  enabled: true
  exclude-reason: >
    blah blah blah

    1. a
    2. b
    3. c

    asdf

with this config:

gap:
  - "."
  - ".subpackages"
  - ".data"
  - ".pipeline"
  - ".update.exclude-reason"

indent: 2

becomes:

update:
  enabled: true
  exclude-reason: >
    blah blah blah

    1. a 2. b 3. c

    asdf

The desire is that the list formatting would be preserved

    1. a
    2. b
    3. c
luhring commented 3 months ago

Gotcha! I'm wondering if this has to do with understanding the YAML spec. Multiline strings behave differently based on the first character used, like | vs. >.

If you replace the > with a |, does this do what you're looking for?

wlynch commented 3 months ago

This does indeed work! TIL - thanks! 🎉