vscode-yaml-sort icon indicating copy to clipboard operation
vscode-yaml-sort copied to clipboard

Sorting messes up some strings

Open Skeeve opened this issue 1 year ago • 1 comments

In my real world example I had a File which just looked similar to YAML in that it had a comment at the top.

So in order to make it a proper YAML, I made the comment a multiline string.

Unfortunately sorting messed the string and the file up.

Here is a working example.

Original YAML:

'!': |
    #####################################
    ##
    ## Zeta:
    ##     - C
    ##     - A
    ##     - B
    ## Beta:
    ##     - B
    ##     - C
    ##     - A
    ## Alpha:
    ##     - A
    ##     - B
    ##     - C
    ##
    #####################################

Zeta:
    - C
    - A
    - B
Beta:
    - B
    - C
    - A
Alpha:
    - A
    - B
    - C

After Sorting

---
'!': |
    #####################################
    ##
Alpha:
  - A
  - B
  - C
Beta:
  - B
  - C
  - A
Zeta:
  - C
  - A
  - B    ##
    ##     - A
    ## Alpha:
    ##     - C
    ##     - A
    ##     - B
    ## Beta:
    ##     - C
    ##     - A
    ##     - B
    ## Zeta:
    ##     - C
    #####################################

Skeeve avatar Sep 24 '24 08:09 Skeeve

I also have strings that are not able to be sorted without breaking,

foo: "{{ lookup('env','FOO') | default('foo') }}"
bar: "{{ lookup('env','BAR') | default('bar') }}"
bar: {{ lookup('env','BAR') | default('bar') }}
foo: {{ lookup('env','FOO') | default('foo') }}

so-jelly avatar Apr 25 '25 13:04 so-jelly