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

Add Config for Array Indentation Spacing #172

Open
codytwinton opened this issue Mar 27, 2019 · 39 comments
Open

Add Config for Array Indentation Spacing #172

codytwinton opened this issue Mar 27, 2019 · 39 comments
Assignees

Comments

@codytwinton
Copy link

I'm working with Jekyll for GitHub Pages, which uses the Ruby gem for parsing YAML. This gem prefers this spacing in Arrays:

---
simple_val: Testing 1
object_val:
  sub_object_val: Testing 2
array_val:
- Testing 3
- Testing 4

However, when auto-formatter is on, this gets converted to:

---
simple_val: Testing 1
object_val:
  sub_object_val: Testing 2
array_val:
  - Testing 3
  - Testing 4

Regardless of preference, it would be great to have an option to disable adding space indention for arrays.

@sledoux
Copy link

sledoux commented Aug 27, 2019

Hi, any plans to add this config?

@CermakM
Copy link

CermakM commented Mar 17, 2020

+1 on this one

@JPinkney
Copy link
Contributor

This all depends on prettier adding this configuration or seeing if they have some api that allows to change array configuration.

@zerda
Copy link

zerda commented Mar 18, 2020

This all depends on prettier adding this configuration or seeing if they have some api that allows to change array configuration.

And per prettier/prettier#4723, Prettier is decided to stay at do indent in mapping.

@telb99
Copy link

telb99 commented Apr 7, 2020

+1 for this, my dev teams preferred option is not to indent

@nlamirault
Copy link

+1 for this. :)

@shamil
Copy link

shamil commented Jun 18, 2020

Also need this option

@alchemistake
Copy link

Another +1

@smyrman
Copy link

smyrman commented Apr 20, 2021

Also an issue when using kustomize edit command (See kubernetes-sigs/kustomize#1395), as it re-indents the file with similar preferences as Jekyll (removing the two additional spaces added by this plugin for an array).

This means that currently, the VS Code formatting plugin and the kustomize edit can't easily be used together.

@smyrman
Copy link

smyrman commented Apr 21, 2021

This all depends on prettier adding this configuration or seeing if they have some api that allows to change array configuration.

And per prettier/prettier#4723, Prettier is decided to stay at do indent in mapping.

Maybe a workable option could be to allow changing the formatter plugin? E.g. yamlfmt (CLI wrapper for https://sourceforge.net/projects/ruamel-yaml/)? Don't know if the exact tool is a good suggestion or not.

@sparhomenko
Copy link

Also an issue when using kustomize edit command

Same for the YAML files edited and committed by Flux v2 image-automation-controller. They've pinpointed it to the behaviour of the underlying library (kyaml) that is also used by kustomize.

yamllint has a configurable setting for sequences indentation (indent-sequences: false), so using it mitigates the problem a bit. It's just a linter though so can only be used to catch the wrong formatting after the fact.

Prettier's decision to enforce a particular style of sequence indentation is questionable to be honest. Automated tools aside, there are plenty of YAML files using non-indented sequences, particularly in the Kubernetes ecosystem.

@ludusrusso
Copy link

Same issue here +1

@tumido
Copy link
Member

tumido commented May 22, 2021

So, I gave it a try and despite Prettier community deciding against using this style, I hope they would agree to make this an option. Please support my PR prettier/prettier#10927

Once/if the PR merges and releases we can just simply update prettier and enable the flag here. 🙂 2. (#519, redhat-developer/yaml-language-server#471)

@AlexZhenWang
Copy link

+1 for this.

@OctavioBR
Copy link

OctavioBR commented Jun 27, 2021

@tumido great work, I'd love to see your PR being merged into prettier.
But as @thorn0 said, prettier is an opinionated formatter that isn't intended to be flexible, avoiding support for too many options. Looks like your prettier/prettier#10927 isn't likely to be merged 😞
I'd suggest redhat-developer/vscode-yaml to use it's own fork of prettier, or any other formatter that may suit all the needs of its users. As you've suggested already, brodybits/prettierx seems a great alternative

@rvansa
Copy link

rvansa commented Dec 17, 2021

Hi, has there been any progress on this? Or known workaround... I was trying to disable formatOnSave feature for YAML completely (as a workaround) but in my case I am editing a Markdown file with YAML snippets and that makes this more complex.

@RafalSkolasinski
Copy link

Same as above, wonder if there is any update here?

bleach31 pushed a commit to bleach31/vscode-yaml that referenced this issue Jan 25, 2022
redhat-developer#172)

* Fix issue: Array item properties are created with the wrong indent #redhat-developer#192

Signed-off-by: andxu <[email protected]>
@mislam01
Copy link

+1 for this.
Most editors adds no indents for lists. Prettier breaks them without this option.

@winkee01
Copy link

winkee01 commented Mar 2, 2022

+1 please provide an option for me to config

@joebowbeer
Copy link

joebowbeer commented May 8, 2022

The path forward is to extend prettierx and then use it instead of prettier?

brodycj/prettierx#382

Normally, I might advocate for extending prettier via prettier-plugin-x, but prettier's philosophical tenet that their opinion cannot be configured seems incompatible with the needs of a yaml plugin for vscode.

@ssbarnea
Copy link
Member

To be honest I am against making non-indented default. I am more than ok with them indented (prettier default). For example on Ansible ecosystem that is also the standard and there are good reasons for it related to visibility/readability.

@RafalSkolasinski
Copy link

RafalSkolasinski commented May 18, 2022

Ansible is using non-intented format for yamls in many places? Just for example on this snippet in docs here https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html we have

---
- name: Update web servers
  hosts: webservers
  remote_user: root

  tasks:
  - name: Ensure apache is at the latest version
    ansible.builtin.yum:
      name: httpd
      state: latest
  - name: Write the apache config file
    ansible.builtin.template:
      src: /srv/httpd.j2
      dest: /etc/httpd.conf

To be clear, I am not against indented lists. Just not in all context. It should be customizable and everyone will be happy :)

@joebowbeer
Copy link

@ssbarnea the selection of a default is a different question. The intent as stated in the title is to add config in order to support the style baked into kustomize and used by a rapidly growing community of Kubernetes users.

@RafalSkolasinski
Copy link

RafalSkolasinski commented Jun 7, 2022

Do we have any hope on resolving this any time soon? This makes the extension unusable for k8s-related development.

@blairham
Copy link

blairham commented Sep 23, 2022

might be worth making an option for which backend formatted to use? There are two camps here, and both are correct. There are the prettier people and the ansible people.

Maybe something like:

"yaml.formatting.engine": "prettier",

or

"yaml.formatting.engine": "pyyaml",

if I get some time maybe I might take a stab at doing this

@ssbarnea
Copy link
Member

ssbarnea commented Sep 23, 2022

@blairham Ansible people group decided to become prettier, so basically the groups you are talking about are more likely named: pyyaml and everyone else ;)

While ansible-lint is making use of pyyaml, it does override its default config in order to make it compatible with prettier rules. Sadly the documentation does not specify this, but we are working on improving it.

Joke aside, I am not against adding a configuration option, but it should be named yaml.formatting.style, defaulting to prettier. The other option would be pyyaml, and that would be a style, not a formatter. Who will write it is another question because prettier does not allow customization and yaml extension will never add a dependency on a python library. Basically to implement the pyyaml styling, we need a ts/js library that can do it, one that is actively maintained.

@joebowbeer
Copy link

@ssbarnea I agree that style is better nomenclature for the option, however, in that case I would omit prettier and pyyaml from its values and use terms descriptive of the style options, rather than the default choices of some tools. Let's be very clear.

The important thing is to provide an option.

Does the prettierx approach have potential?

@Ryu-Z
Copy link

Ryu-Z commented Oct 15, 2022

+1 on this one

@Ryu-Z
Copy link

Ryu-Z commented Oct 15, 2022

now i find a new plugin:kubernetes-yaml-formatter
https://github.com/longkai/kubernetes-yaml-formatter

@mzylak83
Copy link

+1

Was this issue addressed in the end?

@tumido
Copy link
Member

tumido commented Mar 23, 2023

@mzylak83 sadly it was not. This extension relies on Prettier for YAML formatting. Therefore, to make this formatting possible here, we need to add the functionality in upstream Prettier first. And Prettier seems to have decided not to merge my PR for it, see prettier/prettier#10927 for details.

@blairham
Copy link

now i find a new plugin:kubernetes-yaml-formatter https://github.com/longkai/kubernetes-yaml-formatter

Thank you, I can finally ditch this plugin as they are unwilling to work with the community

@kpocius
Copy link

kpocius commented Apr 28, 2023

@blairham, as mentioned numerous time on this issue, including the comment right above yours, this extension is not responsible for the formatting, it uses prettier and they don't want to include the option.

kubernetes-yaml-formatter is a great extension and I use it myself, but I highly suggest keeping both as the former only deals with formatting, while vscode-yaml does so much more: auto-completion, highlighting, validation, etc. Just turn off the formatting on vscode-yaml and use kubernetes-yaml-formatter for that purpose.

@blairham
Copy link

blairham commented Apr 28, 2023

@blairham, as mentioned numerous time on this issue, including the comment right above yours, this extension is not responsible for the formatting, it uses prettier and they don't want to include the option.

kubernetes-yaml-formatter is a great extension and I use it myself, but I highly suggest keeping both as the former only deals with formatting, while vscode-yaml does so much more: auto-completion, highlighting, validation, etc. Just turn off the formatting on vscode-yaml and use kubernetes-yaml-formatter for that purpose.

They own the extension and can provide other formatters or even use the PyYAML package and set the defaults to that of prettier. That is what everyone is asking for instead of relying on a very opinionated formatting tool that does not meet everyone's needs and is not configurable. Thankfully someone has stepped up to the plate and provided that.

@gorkem
Copy link
Collaborator

gorkem commented Jun 23, 2023

We do recognize the problem with the formatter. We have tried to adopt the back-then-popular option prettier on this extension, and we have ended up with the issues we have right now. The yaml-language-server from which this extension inherits its functionality is ubiquitous not only on vscode but also on other editors. Although we want to improve the situation, we can not just throw in yet another formatter. At the moment, we are leaning towards implementing the formatter as part of the yaml-language-server as it already parses the files leading to efficiency benefits, and have access to a high-quality AST.

As evidenced by the number of contributors to the projects, if the community wants to step in and help, we do welcome PRs, as well as issues.

@twskipper
Copy link

+1

@bkalcho
Copy link

bkalcho commented Sep 20, 2023

+1 as https://github.com/transcend-io/terragrunt-atlantis-config do not indent list, and it is essential in a terragrunt-atlantis workflow

@bswck
Copy link

bswck commented Dec 8, 2023

+1

@Realiserad
Copy link

I worked around the problem by adding this vscode extension and disabling the setting yaml.format.enable for this extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests