redhat-developer / redhat-developer/vscode-yaml

yml formatting error cause invalid yml file

Open
#449 0 comments 0 reactions 1 assignee View on GitHub

@msivasubramaniaan is already working on this.

Since Nov 3, 2021.

bug formatter upstream
Dominant language
TypeScript
Stars
829
Forks
260
Avg merge
5h 43m
Merged PRs (30d)
1

Description

Describe the bug

Formatting of this yaml file doesn't yield valid yaml; comment confusion

! Please note: I don't know that my input is strictly yaml syntax, but Python yaml does read it correctly.

import yaml
with open("yml_format_bug.yml") as fp:
    yaml.safe_load(fp)
input yaml
first: 123

v1: {
    file: PYTHON_TO_RUN_REMOTELY, 
    type:   env # A type of 'env' pulls the value from an environment variable.
            # Only works for file: and path: values., absolute: true
}

v2:
    file: PYTHON_TO_RUN_REMOTELY
    type:   env # A type of 'env' pulls the value from an environment variable.
            # Only works for file: and path: values., absolute: true

last: 123

Expected Behavior

I don't know what the correct format should be, but it should give valid yaml in any case. Here is an example of what it might look like. I don't particularly care the format

first: 123

v1: { file: PYTHON_TO_RUN_REMOTELY, type: env # A type of 'env' pulls the value from an environment variable.
      # Only works for file: and path: values., absolute: true 
}

v2:
  file: PYTHON_TO_RUN_REMOTELY
  type:
    env # A type of 'env' pulls the value from an environment variable.
    # Only works for file: and path: values., absolute: true

last: 123

Current Behavior

Closing curly gets put into comment causing yaml to be invalid.

first: 123

v1: { file: PYTHON_TO_RUN_REMOTELY, type:
      env # A type of 'env' pulls the value from an environment variable.
      # Only works for file: and path: values., absolute: true }

v2:
  file: PYTHON_TO_RUN_REMOTELY
  type:
    env # A type of 'env' pulls the value from an environment variable.
    # Only works for file: and path: values., absolute: true

last: 123

Steps to Reproduce

Create new file containing my "Input yaml" above.
Change file type to yaml if necessary.
Press Ctrl + Shift + I in vscode with extension installed and enabled.

Environment

[X] Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.