yamlfix icon indicating copy to clipboard operation
yamlfix copied to clipboard

Comments in lists during style change are not placed properly

Open Rizhiy opened this issue 1 year ago • 6 comments

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
------------------------------------------------------------------

Rizhiy avatar Jan 06 '23 19:01 Rizhiy

Hi @Rizhiy thanks for taking the time to open the issue. @marcules will you be able to take a look on this bug?

lyz-code avatar Jan 09 '23 10:01 lyz-code

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

lyz-code avatar Jan 13 '23 16:01 lyz-code

The problem is that currently output is not a valid yaml. Not changing the list is fine with me.

Rizhiy avatar Jan 13 '23 16:01 Rizhiy

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"

lyz-code avatar Jan 16 '23 18:01 lyz-code

I will check the latest, I'm still on 1.3.1 because of #211

Rizhiy avatar Jan 16 '23 19:01 Rizhiy

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
------------------------------------------------------------------

Rizhiy avatar Jan 16 '23 21:01 Rizhiy