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

List Values Are Unindented #25

Closed
FelicianoTech opened this issue Sep 18, 2017 · 3 comments
Closed

List Values Are Unindented #25

FelicianoTech opened this issue Sep 18, 2017 · 3 comments

Comments

@FelicianoTech
Copy link

FelicianoTech commented Sep 18, 2017

I can't tell if this is expected, or a bug. Let's say I have the following Yaml file:

title: "My Book"
tags:
  - "adventure"
  - "novel"

and I run the following command: `yaml write -i mybooks.yml author "J.K. Rowling"

The updated Yaml file now looks like:

title: My Book
tags:
- adventure
- novel
author: J.K. Rowling

This GitHub Issue is due to the fact that the 'tags' list has lost its indention. That didn't look like valid Yaml to me so I ran it through http://www.yamllint.com/. While the Yaml did validate, the tags list was "corrected" to the indention I had it previously. So is this a bug?

Also, as you can see, the quotes around the strings are gone. I can see from this issue that it's because of the parser so I guess we can't do anything about it. Sucks though.

kenjones-cisco added a commit that referenced this issue Sep 26, 2017
The format produced by `gopkg.in/yaml.v2` produces output while valid
is not easy to read especially for arrays.
Adds formatter to handle formatting the marshalled yaml content.
Applies similar logic used by `encoding/json.Indent`.

Resolves: #25
@varac
Copy link

varac commented Aug 23, 2018

Hej, any updates on this ? This behaviour is indeed not great. Yaml lists should be indented although technically they don't have to. I saw the referenced PR #43 got closed, not merged.

@mikefarah
Copy link
Owner

The latest release https://github.com/mikefarah/yq/releases/tag/3.1.0 has a indent flag, if this is set to 4 or greater then the lists will be indented - where as an indent of 2 is not.

Not sure why this is the case - this is what the underlying yaml parser does...

@ringerc
Copy link

ringerc commented Dec 6, 2022

An unrelated yq tool https://kislyuk.github.io/yq/ has the --indentless-lists option. This would be handy to have when working with 4-space indented yaml without list indents to minimise diffs.

Not a biggie as it's possible to use a yaml pretty-printer on it after.

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

4 participants