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

v3: (Encoder) setting indentation for sequences #661

Closed
starkers opened this issue Oct 3, 2020 · 3 comments
Closed

v3: (Encoder) setting indentation for sequences #661

starkers opened this issue Oct 3, 2020 · 3 comments

Comments

@starkers
Copy link

starkers commented Oct 3, 2020

Heya ..amateur gopher here so go easy on me please..

I'm looking at the code on https://github.com/wangkuiyi/yamlfmt which is using v3

With a (eg stdout) stream I can see how the code uses an Encoder which is great, and I can easily see how the indent is modified via: https://pkg.go.dev/gopkg.in/yaml.v3#Encoder.SetIndent

What I'm trying todo however is set the indent level for the list/items.. EG:
currently:

doc:
  key: foo
  items:
    - one
    - two

but I'd like a more compact:

doc:
  key: foo
  items:
  - one
  - two

I cannot see any such receiver function on the *Encoder so I'm not certain how to do this am I missing something or is it just not implemented?

@sylr
Copy link
Contributor

sylr commented Nov 24, 2020

In v3 the indentation has been changed and no option to revert to a v2 like output is provided.

Voices have already raised this problem, see :

But so far the maintainer does not seem to be inclined to either revert to the v2 formatting (that we all know about) or at least provide a way to configure the it.

@niemeyer
Copy link
Contributor

Indeed, at least not at this time we won't have an API in v3 for that, and the reason is that v3 makes The formatting in v2

@niemeyer
Copy link
Contributor

The formatting in v2 was inconsistent in several ways with many edge cases. In v3 we've changed it to simply make it not special: every depth level is indented by the space amount of spacing, regardless of its type.

I understand that some people will be used to the old formatting, but on this basis alone it'd be hard to evolve anything.

pivotaljohn pushed a commit to carvel-dev/ytt that referenced this issue Mar 22, 2022
- yaml.v3 author refuses to support special indentation for sequences;
  adjust tests containing arrays to indent.
  (see also: go-yaml/yaml#661)
pivotaljohn pushed a commit to carvel-dev/ytt that referenced this issue Apr 8, 2022
- yaml.v3 author refuses to support special indentation for sequences;
  adjust tests containing arrays to indent.
  (see also: go-yaml/yaml#661)
pivotaljohn pushed a commit to carvel-dev/ytt that referenced this issue Apr 22, 2022
- yaml.v3 author refuses to support special indentation for sequences;
  adjust tests containing arrays to indent.
  (see also: go-yaml/yaml#661)
pivotaljohn pushed a commit to carvel-dev/ytt that referenced this issue May 13, 2022
- yaml.v3 author refuses to support special indentation for sequences;
  adjust tests containing arrays to indent.
  (see also: go-yaml/yaml#661)
pivotaljohn pushed a commit to carvel-dev/ytt that referenced this issue May 23, 2022
- yaml.v3 author refuses to support special indentation for sequences;
  adjust tests containing arrays to indent.
  (see also: go-yaml/yaml#661)
pivotaljohn pushed a commit to carvel-dev/ytt that referenced this issue May 24, 2022
- yaml.v3 author refuses to support special indentation for sequences;
  adjust tests containing arrays to indent.
  (see also: go-yaml/yaml#661)
pivotaljohn pushed a commit to carvel-dev/ytt that referenced this issue Jun 7, 2022
- yaml.v3 author refuses to support special indentation for sequences;
  adjust tests containing arrays to indent.
  (see also: go-yaml/yaml#661)
pivotaljohn pushed a commit to carvel-dev/ytt that referenced this issue Jul 19, 2022
- yaml.v3 author refuses to support special indentation for sequences;
  adjust tests containing arrays to indent.
  (see also: go-yaml/yaml#661)
GabrielNagy added a commit to ubuntu/adsys that referenced this issue Mar 24, 2023
With yaml.v3 it appears the formatting has changed and there's no way to
revert back to the previous implementation. See
go-yaml/yaml#661.

Because of this, the easiest thing we can do is refresh the files to
match the v3 output.
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

3 participants