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

Array whitespace is changed between parse and stringify #570

Closed
pksunkara opened this issue Aug 23, 2024 · 8 comments
Closed

Array whitespace is changed between parse and stringify #570

pksunkara opened this issue Aug 23, 2024 · 8 comments

Comments

@pksunkara
Copy link

pksunkara commented Aug 23, 2024

Describe the bug
When I am parsing a YAML and stringifying it afterward, the whitespace in an array changes.

To Reproduce

Before:

on: [pull_request]

After:

on: [ pull_request ]

Expected behaviour

The after file should be the same as before

Versions (please complete the following information):

  • node: 22
  • yaml: 2.5.0
@pksunkara pksunkara added the bug Something isn't working label Aug 23, 2024
@eemeli
Copy link
Owner

eemeli commented Aug 23, 2024

It's retained in the document that you get from parseDocument; the formatting is not retained in the JS representation.

@pksunkara
Copy link
Author

Oh, that makes sense. Let me see if I can use parseDocument and fix it.

@pksunkara
Copy link
Author

I haven't fully confirmed because I am still revamping my other logics, but it looks like the "After" version is adding spaces though.

on: [ pull_request ]

@pksunkara
Copy link
Author

Yup, I can confirm that the spaces choice between in the square brackets in array is not being preserved.

@eemeli
Copy link
Owner

eemeli commented Sep 2, 2024

Normalising whitespace is done intentionally; information about it is not retained in the parsed document.

@pksunkara
Copy link
Author

In that case,

  1. Do you plan to add support for it? (I might be willing to contribute here to this case.)
  2. Is this the same cause for Multi line values formatting is not preserved when parsing and stringifying documents #572 too?

@eemeli
Copy link
Owner

eemeli commented Sep 2, 2024

  1. No; if you need to retain whitespace, you should be applying your changes to the CST and serialising that: https://eemeli.org/yaml/#working-with-cst-tokens
  2. Same root cause, but details differ. I'll comment on that issue separately.

@pksunkara pksunkara changed the title Array style choice is not preserved between parse and stringify Array whitespace is not preserved between parse and stringify Sep 24, 2024
@pksunkara pksunkara changed the title Array whitespace is not preserved between parse and stringify Array whitespace is changed between parse and stringify Sep 24, 2024
@eemeli
Copy link
Owner

eemeli commented Oct 5, 2024

Closing, as there's nothing actionable here and the current behaviour is intentional.

@eemeli eemeli closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2024
@eemeli eemeli removed the bug Something isn't working label Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants