Skip to content

Array-indent not maintained between parseDocument/toString #283

@grantila

Description

@grantila

Describe the bug

First of all, thanks for an awesome yaml parser/stringifyer! I just wrote this this weekend: yaml-diff-patch using this library to allow modifying a yaml using JSON patches.

I'm not sure if this is considered a bug, but I'd very much hope so. The library would be most useful if it maintains as much as possible from the source yaml when parsing the document into AST/CST so that stringifying it produces the exact same result. This means that minimal (or no) modifications to the AST would produce a minimal (or no) diff when text diffing the original yaml with the modified. In other words, only what you change, would be part of the final diff.

To Reproduce

The following:

a:
- b: c

when parseDocument -> toString produces:

a:
  - b: c

Expected behaviour

I totally understand how this looks better. I also totally understand that a document with both these indentations in different places is pretty ugly, and being able to "reformat" it is great. However, being able to maintain all blocks' indentations individually as-is makes more sense when trying to make a minimal diff that only touches what it needs.

I noticed (in 1.10.2) that quite a few things get re-organized, long lines get chopped into multiple shorter, long one-line arrays get split into line-by-line arrays etc. I haven't tried that in 2.0 yet, so you can ignore that for now.

Versions (please complete the following information):

  • Environment: Node.js 14.15.1
  • yaml: 1.10.2 and 2.0.0-6

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions