de-jcup / eclipse-yaml-editor

Eclipse YAML editor
https://marketplace.eclipse.org/content/yaml-editor
Apache License 2.0
34 stars 10 forks source link

dictionary key is converted to boolean value by formatter #85

Closed klei1984 closed 4 years ago

klei1984 commented 4 years ago

I am setting up a github actions script which is in yaml format. Actions has a specific keyword set which relies on <key>: <value> syntax. See this page for all the keywords.

The on.push.branches event is basically described with the below yaml code:

name: GitHub CI

on:
  push:
    branches:
    - master
    tags: [ '**' ]

I am using version 1.6.1 of the editor which converts the on: key to the boolean true value as in the below result:

name: GitHub CI
true:
  push:
    branches:
    - master
    tags:
    - '**'

I did not check what github actions actually do with such a script, but my assumption is that keys are not supposed to be replaced by boolean values.

Am I missing something? I found a similar issue here but that is another tool and another context.

Or could it be that the yaml format used by Github is not actually compliant to either version of the standard and thus I should not try to use a yaml editor for such scripts?

de-jcup commented 4 years ago

I tried out the formatting and had some odd result as you...

Problem description

The problem is, that under the hood snake-yaml parser is used to load the yaml document from string content into a yaml object and after this the object is dumped back to a string.

So we got String -> Yaml-Object ->String

"on" is recognized by snake-yaml as a boolean value... so inside the loaded yaml object its recognized as "boolean:true" and when doing the dump the output is switched to "true".

I have looked into the sources and found a potential solution: snake-yaml gives many possibilities to use specialized renderers and resolvers. Maybe for formatting there should customized variants which could avoid the problem.

de-jcup commented 4 years ago

Just released V1.6.2 on eclipse marketplace

Formatter preference page has got a new option "prevent type conversion" which is enabled per default:

image

When this is enabled, your example is formatted like next screenshots: image becomes: image

klei1984 commented 4 years ago

Thanks a lot!