redhat-developer / redhat-developer/vscode-yaml

Formatting breaks with default settings when yaml.format.printWidth is 80 but key is longer

Open
#1,021 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

Certain YAML contents are erroneously converted into a weird non-yaml ternary-expression-like string.

Expected Behavior

Formatting should generate valid YAML even for long keys.

Current Behavior

The default yaml.format.printWidth is 80 characters. If the key is longer, questionmarks are added before keys when formatting.

For example, this:

resource.customizations.ignoreDifferences.admissionregistration.k8s.io_MutatingWebhookConfiguration: |
      jqPathExpressions:
        - '.webhooks[]?.clientConfig.caBundle'

Gets formatted into this:

? resource.customizations.ignoreDifferences.admissionregistration.k8s.io_MutatingWebhookConfiguration
    : |
      jqPathExpressions:
        - '.webhooks[]?.clientConfig.caBundle'

But this:

resource.customizations.ignoreDifferences.admissionregistration.k8s.io_Mutating: |
      jqPathExpressions:
        - '.webhooks[]?.clientConfig.caBundle'

Turns into:

resource.customizations.ignoreDifferences.admissionregistration.k8s.io_Mutating:
  |
  jqPathExpressions:
    - '.webhooks[]?.clientConfig.caBundle'

Steps to Reproduce

  1. Create YAML with contents:
    resource.customizations.ignoreDifferences.admissionregistration.k8s.io_MutatingWebhookConfiguration: |
      jqPathExpressions:
        - '.webhooks[]?.clientConfig.caBundle'
    
  2. Try formatting and see results:
    ? resource.customizations.ignoreDifferences.admissionregistration.k8s.io_MutatingWebhookConfiguration
    : |
      jqPathExpressions:
        - '.webhooks[]?.clientConfig.caBundle'
    

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)

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.

Research direction

Reproduce the formatting behavior using the YAML examples and the default yaml.format.printWidth setting. Trace the formatter entry point responsible for wrapping long keys, then verify that formatting preserves valid YAML for both long and shorter keys.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode, yaml
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.