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

yamlfmt does not retain indent in >-(Line Folding) by default #182

Closed
kachick opened this issue May 16, 2024 · 3 comments
Closed

yamlfmt does not retain indent in >-(Line Folding) by default #182

kachick opened this issue May 16, 2024 · 3 comments

Comments

@kachick
Copy link
Contributor

kachick commented May 16, 2024

For actual example from .goreleaser.yml in this repository

With yamlfmt 0.12.1

cat <<'EOF' | yamlfmt -in
archives:
  - name_template: >-
      {{ .ProjectName }}_
      {{- .Version }}_
      {{- title .Os }}_
      {{- if eq .Arch "amd64" }}x86_64
      {{- else if eq .Arch "386" }}i386
      {{- else }}{{- .Arch }}{{- end }}
      {{- if .Arm }}v{{- .Arm }}{{- end }}
EOF

It outputs

archives:
  - name_template: >-
      {{ .ProjectName }}_ {{- .Version }}_ {{- title .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{- .Arch }}{{- end }} {{- if .Arm }}v{{- .Arm }}{{- end }}

From yaml spec

Line folding allows long lines to be broken for readability, while retaining the semantics of the original long line. If a line break is followed by an empty line, it is trimmed; the first line break is discarded and the rest are retained as content.

If this behavior is correct, I think we don't need any >- syntax in YAML.

@braydonk
Copy link
Collaborator

Hi @kachick do you have scan_folded_as_literal set here? I added that setting to deal with this problem.

@kachick
Copy link
Contributor Author

kachick commented May 16, 2024

Oh... sorry, I didn't understand this flag 🙇‍♂️

Perfectly resolved!

(But I dont't know when scan_folded_as_literal: false maybe useful... 🤔)

@kachick kachick closed this as completed May 16, 2024
@kachick kachick changed the title yamlfmt does not retain indent in >-(Line Folding) yamlfmt does not retain indent in >-(Line Folding) by default May 16, 2024
@braydonk
Copy link
Collaborator

No problem, I understand it's not very well named. I was really struggling to come up with a name for it. Realistically I think it should default to on. I have a general rule that when any feature is a result of me changing/adding something to my fork of the yaml library, I don't default it to on in case there is a niche case where it broke. I could probably come up with a better solution for leaving things default off at first and having a schedule for defaulting them on after not receiving issues about it for long enough. I'll think about a plan for this going forward!

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

2 participants