vscode-yaml
vscode-yaml copied to clipboard
Formatter should not squash multiline string values
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
- 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"
- Save the file.
Environment
- [x] Windows
- [ ] Mac
- [x] Linux
- [ ] other (please specify)
Any eta on this one, very annoying
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.
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.
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