pantoniou / libfyaml

Fully feature complete YAML parser and emitter, supporting the latest YAML spec and passing the full YAML testsuite.
MIT License
241 stars 74 forks source link

Preferred defaults for `fy-tool -m dejson` #47

Closed ingydotnet closed 2 months ago

ingydotnet commented 2 years ago

First off dejson is a bad name for this. How about yamlfmt, yfmt,, tidy or something? JSON has nothing to do with this.

So here are some changes to the default emitter format I'd like to see...

$ echo $'foo:\n- bar' | fy-tool -m yamlfmt -
foo:
- bar
$ echo $'foo:\n- "bar\\nbaz\\nboom\\n"' | fy-tool -m yamlfmt -
---
foo:
- |
  bar
  baz
  boom

Do those for starters.

In general @perlpunk's yamlpp-load-dump --preserve 0 does a good job for this kind of formatting. You can install with cpanm YAML::PP.

ingydotnet commented 2 years ago

Here's some general heuristics:

fy-tool already seems to fold plain scalars. yaml-pp-load doesn't. I think that folding is nice, so keep that.

$ echo $'foo:\n- " x "' | fy-tool -m dejson -
foo:
  - " x "

I'd like to see single quotes not double quotes. also you don't seem to fold quoted scalars like you do for plain. That's a shame. :)

ingydotnet commented 2 years ago

Also yamlpp-load-dump --preserve 0 emits --- at start. This is preferred to state (not too loudly) that this is YAML.

Also start top level scalars on the --- line

$ echo $'foo\nbar' | yamlpp-load-dump --preserve 0
--- foo bar
pantoniou commented 2 years ago

Addressed most of these with the 21747066c6684f3b09c60c72fe5dda537706dc82 and de49581ad0cf52c103f9c21f0bffe7e76ff03d05 commits.

fy-tool now accepts -mpretty (or -myamlfmt as an alias).

I'm not so gung-ho to make single quotes as the default for scalars that can't be plain. I'm an old C person and when I see single quotes my lizard brain goes to char mode...

pantoniou commented 2 months ago

Closing since this is be OK now.