vscode-yaml icon indicating copy to clipboard operation
vscode-yaml copied to clipboard

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

Open gnadaban opened this issue 9 months ago • 0 comments

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
  • [x] Mac
  • [ ] Linux
  • [ ] other (please specify)

gnadaban avatar May 07 '24 12:05 gnadaban