google / yamlfmt

An extensible command line tool or library to format yaml files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adds newline into folded block scalar with extra indentation

Lykos153 opened this issue · comments

I have the following block:

- name: Configure and restart kubelet
  when: >
    ( _allow_disruption | default(False)
        or do_upgrade | default(False)
        or _init_cluster | default(False))
    and not k8s_kubelet_disable_customizations | default(False)

After each run of yamlfmt, a new line is added like so:

- name: Configure and restart kubelet
  when: >
    ( _allow_disruption | default(False)

        or do_upgrade | default(False)
        or _init_cluster | default(False))
    and not k8s_kubelet_disable_customizations | default(False)
- name: Configure and restart kubelet
  when: >
    ( _allow_disruption | default(False)


        or do_upgrade | default(False)
        or _init_cluster | default(False))
    and not k8s_kubelet_disable_customizations | default(False)
- name: Configure and restart kubelet
  when: >
    ( _allow_disruption | default(False)



        or do_upgrade | default(False)
        or _init_cluster | default(False))
    and not k8s_kubelet_disable_customizations | default(False)

I'm not sure if this might be related to #63

Thanks for making an issue!

I'm not sure if this is related to #63 or not, but both definitely indicate some strangeness in how yaml.v3 decodes scalars.

I have forked the yaml library so I can actually look at this and see if I can make a low-blast-radius fix. Unfortunately I can't make any timeline promises, trying to figure out/fix stuff with the yaml library is unpredictable time wise. Sorry about that, but it's on my radar!

The fix for this is in main and will be in v0.7.0! It will be behind a new formatter option, scan_folded_as_literal.