chainguard-dev / yam

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

handle formatting of empty but not nil structs #65

Closed rawlingsj closed 2 months ago

rawlingsj commented 3 months ago

Initially this is a test case to demonstrate what I'm hoping for. The test will fail, not 100% sure where to fix, maybe in encoder.go? I tried adding the below to the marshalMapping function but we get an extra indented line so figure there's more to it.

    if len(node.Content) == 0 {
        // This is an empty mapping node, we should return "{}"
        return []byte("{}\n"), nil
    }

Here's an example of what happens without this support https://github.com/rawlingsj/wolfi-os/pull/2064/files#diff-c1e7e6d93bdcfdbf44020ead40b6f83e46b82b28422c8a70fd48accc5e6acdd0L44