Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dictionary key is converted to boolean value by formatter #85

Closed
klei1984 opened this issue Jan 28, 2020 · 3 comments
Closed

dictionary key is converted to boolean value by formatter #85

klei1984 opened this issue Jan 28, 2020 · 3 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@klei1984
Copy link

klei1984 commented Jan 28, 2020

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
Copy link
Owner

de-jcup commented Jan 30, 2020

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 de-jcup self-assigned this Jan 30, 2020
@de-jcup de-jcup added bug Something isn't working enhancement New feature or request labels Jan 30, 2020
@de-jcup de-jcup added this to the 1.6.2 milestone Jan 30, 2020
de-jcup added a commit that referenced this issue Jan 30, 2020
- We use now a dedicated resolver to prevent boolean type conversion
  when marshalling yaml content to objects for formatting.
- Per default prevention is enabled, but it can be turned off in
  formatter preferences (if necessary)
- also behaviour of AbstractYamlEditorFoldingHandler was changed
  so no longer NPE on startup possible
@de-jcup
Copy link
Owner

de-jcup commented Jan 30, 2020

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
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants