redhat-developer / vscode-yaml

YAML support for VS Code with built-in kubernetes syntax support
MIT License
644 stars 218 forks source link

Formatter should not squash multiline string values #987

Open tidux opened 9 months ago

tidux commented 9 months ago

Describe the bug

I'm attempting to embed a 50+ line INI file in a ConfigMap as a string. Whenever I save the file that section loses all of its formatting and it gets squashed into a single line sprinkled with literal \n and "magic line" comment blocks. This makes the embedded INI file unreadable for editing the configuration values so I have to go in and manually find-replace the formatting back how it was and re-indent the block.

Expected Behavior

Format-on-save should not mangle multiline strings. Newlines exist for a reason.

Current Behavior

Format-on-save mangles my strings.

Steps to Reproduce

  1. Create the following YAML file in VSCode:
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: foo
    namespace: bar
    data:
    baz.ini: |+
    "[section1]
    a = b
    x = y
    [section2]
    foo=bar"
  2. Save the file.

Environment

asmirnoff commented 5 months ago

Any eta on this one, very annoying

EronWright commented 5 months ago

A workaround is to select "Format Document With..." on the context menu, and choose "YAML" rather than "Kubernetes YAML". Seems it is the latter extension that's responsible for this problem.

chrisbecke commented 2 months ago

Thats not a workaround. Its the fix. The "kennylong.io" "kubernetes yaml formatter" overrides the RedHat formatter and unwraps multiline strings. Uninstall it and everything starts working.

juliusl commented 2 months ago

Pasting this here to improve discoverability of this issue: "#magic_^^line"

It looks like the issue causing this issue is the above extension (which uses https://github.com/google/yamlfmt underneath the hood) and also if there is a trailing space at the end of a multiline yaml string

https://github.com/google/yamlfmt/issues/86