chainguard-dev / yam

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

Alphabetize packages by convention, update existing modules, and validate #27

Closed vaikas closed 1 year ago

vaikas commented 1 year ago

It would be nice to have packages alphabetized so it's easier to find if a particular package is there or not visually. Add verbiage saying this is the convention, update existing packages (this could be done lazily), add a presubmit check to enforce this.

luhring commented 1 year ago

Awesome idea! I love it.

Since yam operates on YAML generically, we could have an implementation that's generic. Maybe something like "sort path expressions", similar to how today you can specify "gap path expressions", where matching YAML elements have their child elements gapped with empty lines.

E.g. given a file foo.yaml:

name: ville
favorite-dans:
  - luhring
  - lorenc

You could run yam --sort '.favorite-dans' foo.yaml (or the equivalent via a yam config file) to produce:

name: ville
favorite-dans:
  - lorenc
  - luhring

(Which would hurt my feelings, but at least sorted alphabetically...)

WDYT?

vaikas commented 1 year ago

Yes! I was hoping to have ways of specifying that certain arrays need to be sorted indeed.

luhring commented 1 year ago

Closing per https://github.com/chainguard-dev/yam/pull/28 but lmk if there's more to this!