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

Multi line values formatting is not preserved when parsing and stringifying documents #572

Open
pksunkara opened this issue Sep 2, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@pksunkara
Copy link

pksunkara commented Sep 2, 2024

Describe the bug
A clear and concise description of what the bug is.

Running parseDocument(content).toString() on the following:

run: aws cloudfront create-invalidation
  --distribution-id ABCDEF
  --paths '/index.html'

is changing it to:

run: aws cloudfront create-invalidation --distribution-id ABCDEF --paths
  '/index.html'

Expected behaviour

The original value should be preserved exactly as it is.

Versions (please complete the following information):

yaml and node latest

@eemeli
Copy link
Owner

eemeli commented Sep 2, 2024

The newlines in the plain scalar are collapsed into spaces, so they're lost in the parsing. They are of course in the CST, but retaining them for Document stringification as well could be nice, though tricky to do without impacting users who don't care about them.

Preserving multi-line values "exactly as it is" is also rather tricky, as the structure around the node can change, and it can become more or less indented as a result.

There could be something in the stringifier that might check the srcToken value (the node's CST token, retained if keepSourceTokens: true is set), re-parse that to see if it matches the current value, and if so, determine a common indent to remove from each line past the first, and then use that in the serialization. There probably are a bunch of corner cases here that I'm not thinking of right away, but I'd be happy for someone to look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants