mrm icon indicating copy to clipboard operation
mrm copied to clipboard

Yaml formatting not preserved

Open ext opened this issue 3 years ago • 0 comments

When using the builtin yaml helpers the formattin of the file is not preserved. While it technically doesn't matter how the file is formatted it helps humans to read and understand.

It is also often common convention, in this case I use Gitlab CI which uses a blank line to separate different tasks. I would assume similar conventions is used elsewhere in other CI setups.

Steps to reproduce

Given a yaml file such as:

image: node:14

stages:
  - test
  - build
  - release

foo:
  stage: test
  something: [1, 2, 3]
  script:
    - foo

bar:
  stage: build
  script:
    - bar

baz:
  stage: release
  script:
    - baz

As an example, lets say the mrm task uses

file.set('image', 'node:16');
file.save();

Actual results

Most notably, all the blank lines separating the tasks has been removed but there are other subtle changes

image: 'node:16' # this has turned into a string
stages:
  - test
  - build
  - release
foo:
  stage: test
  something: # this has been converted from [ .. ] to -
    - 1
    - 2
    - 3
  script:
    - foo
bar:
  stage: build
  script:
    - bar
baz:
  stage: release
  script:
    - baz

Expected results

All formatting should be intact, at least on lines which otherwise hasn't changed.

I have not checked the implementation but I assume all this has to do with serialization, perhaps it is better to handle it as a syntax tree?

ext avatar Jun 20 '21 16:06 ext