yamlfix icon indicating copy to clipboard operation
yamlfix copied to clipboard

Disabling `explicit_start` breaks multidocument files

Open nadiamoe opened this issue 1 year ago • 1 comments

Description

When explicit_start is set to false, yamlfix strips all document separators from a file, potentially breaking it.

Steps to reproduce

Consider the following file with two documents (test.yaml):

document: one
---
document: two

Running yamlfix with explicit_start set to false will break this file:

16:10:20 /tmp/roobre $> cat test.yaml | YAMLFIX_EXPLICIT_START=false ~/.local/share/nvim/mason/bin/yamlfix -
[+] YamlFix: Fixing files
[+] Fixed <stdin>
document: one
document: two

This does not happen if explicit_start is true (default):

16:10:56 /tmp/roobre $> cat test.yaml | ~/.local/share/nvim/mason/bin/yamlfix -
[+] YamlFix: Fixing files
[+] Fixed <stdin>
---
document: one
---
document: two

I think that if explicit_start is set to false, yamlfix should keep existing separators to avoid breaking valid files.

If possible, I think it would be even better if there was a way (explicit_start or otherwise) to tell yamlfix to not mess with the explicit start altogether: Keep it if exists, do not add it if it doesn't, do nothing with other (non-start) separators.

Environment

16:13:21 /tmp/roobre $> ~/.local/share/nvim/mason/bin/yamlfix --version
------------------------------------------------------------------
     yamlfix: 1.16.0
     Python: 3.11.6
     Platform: Linux-6.7.1-arch1-1-x86_64-with-glibc2.38
------------------------------------------------------------------

nadiamoe avatar Jan 30 '24 15:01 nadiamoe

facing the same issue

fredleger avatar Mar 05 '24 11:03 fredleger