Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Superfluous comma in flow style #110

Open
woodgiraffe opened this issue Apr 9, 2023 · 2 comments
Open

Bug: Superfluous comma in flow style #110

woodgiraffe opened this issue Apr 9, 2023 · 2 comments
Labels
yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix.

Comments

@woodgiraffe
Copy link

woodgiraffe commented Apr 9, 2023

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!

@woodgiraffe woodgiraffe changed the title Bug: Superfluous comma in flow Bug: Superfluous comma in flow style Apr 9, 2023
@braydonk
Copy link
Collaborator

braydonk commented May 16, 2023

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.

@braydonk braydonk added the yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix. label Oct 25, 2023
@nicholasklem
Copy link

Having

- {foo: bar,}

Then yamllint of course complains about

warning  too few spaces after comma  (commas)

so we have an eternal fight 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix.
Projects
None yet
Development

No branches or pull requests

3 participants