yamlfix
yamlfix copied to clipboard
Comments in lists during style change are not placed properly
Description
When changing list style from block to flow, comments are not placed properly.
Steps to reproduce
---
list:
# Comment
- echo "Test"
Current behavior
---
list:
# Comment
[echo "Test"]
Desired behavior
---
# Comment
list: [echo "Test"]
Environment
------------------------------------------------------------------
yamlfix: 1.3.1
Python: 3.10.8
Platform: Linux-5.15.0-56-generic-x86_64-with-glibc2.31
------------------------------------------------------------------
Hi @Rizhiy thanks for taking the time to open the issue. @marcules will you be able to take a look on this bug?
Now that I'm looking more closely to your desired behaviour, I don't agree that the comment should be moved above the list
element in this case it may make sense but if the list starts to be bigger and it goes back to block style
instead of flow style
the program won't be able to move the comment back below the list
element.
Therefore I'd say that in this case the source should be left as it was and not do any transformation
The problem is that currently output is not a valid yaml
.
Not changing the list is fine with me.
I thought that @fortin-alex #212 would solve this issue. Until it's solved you can use:
---
list:
- echo "Test" # Comment
or
---
list:
- echo "Test"
# Comment
or
---
# Comment
list:
- echo "Test"
I will check the latest, I'm still on 1.3.1 because of #211
Just checked, still produces invalid yaml on 1.5.0
:
------------------------------------------------------------------
yamlfix: 1.5.0
Python: 3.10.8
Platform: Linux-5.15.0-56-generic-x86_64-with-glibc2.31
------------------------------------------------------------------