google / yamlfmt

An extensible command line tool or library to format yaml files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Superfluous comma in flow style

woodgiraffe opened this issue · comments

Version: latest

To reproduce:

printf "---\n- {foo: bar}\n\n" | yamlfmt -formatter "include_document_start=true" -formatter "retain_line_breaks=true" -

Actual Input:

---
- {foo: bar}

Actual Output:

---
- {foo: bar,}

Expected Output:

---
- {foo: bar}


Also note that the following works fine:

printf "---\n- {foo: bar}\n" | yamlfmt -formatter "include_document_start=true" -formatter "retain_line_breaks=true" -

Thanks for your work on this!

Hi @woodgiraffe thank you for making an issue. I apologize for the delay in addressing it, as I got extremely busy and didn't have time to look at this project for a while.

This is a completely baffling edge case. It seems that if all these requirements are satisfied:

  • There is a document start
  • There is more than one newline at the end of the file
  • There is a comment below the flow style block (this is how the retain_line_breaks hack works under the hood so that's why that setting being on triggers it)

Then for some reason the yaml library will add this extra comma. I am completely lost for this at the moment, I have no idea why this happens or how to fix it.

I'll keep trying, I know the inconsistent behaviour is frustrating. I can't promise when this will get fixed though unfortunately cause it's just so strange. I apologize for that! Thank you again for bringing it to my attention.