google / yamlfmt

An extensible command line tool or library to format yaml files.
Apache License 2.0
1.13k stars 43 forks source link

After formatting, the character "," (that is, a comma) appears at the very end before "}" #195

Open Andy-Solo opened 1 month ago

Andy-Solo commented 1 month ago

After formatting, the character "," (that is, a comma) appears at the very end before "}":

loop:

or

with_items:
- {path: /root/.bashrc, regex: '[\033[01;32m\]', replace: '[\\033[01;31m\]',}
braydonk commented 1 month ago

Hi @Andy-Solo thanks for opening a feature request.

I won't have time to work on this in the near future. I'll put an explanation for what I think needs to be done, for either my future self or someone else who might be able to pick it up.

Getting this to work might be non-trivial. I think this is the code that produces the comma for flow mapping nodes: https://github.com/braydonk/yaml/blob/10bcc859418b821726f51e2beb7406449cf0b4a2/emitterc.go#L712-L716

It's hard to tell by reading if that's the spot that matters here, but that's my best guess.

Somehow the parser would need to figure out that the current node is the final flow mapping value, and then optionally emit the comma depending on a yaml_emitter config value. Might be nasty to get working, but perhaps someone other than me will be able to do something easier than what I'm suggesting.

sdx23 commented 3 weeks ago

( duplicate of #110 )