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

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

Open
1 of 4 tasks
gnadaban opened this issue May 7, 2024 · 0 comments
Open
1 of 4 tasks

Comments

@gnadaban
Copy link

gnadaban commented May 7, 2024

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)
@gnadaban gnadaban changed the title Formatting breaks for keys longer than 79 characters Formatting breaks with default settings when yaml.format.printWidth is 80 but key is longer May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant