vscode-yaml
vscode-yaml copied to clipboard
Add Config for Array Indentation Spacing
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.
Hi, any plans to add this config?
+1 on this one
This all depends on prettier adding this configuration or seeing if they have some api that allows to change array configuration.
This all depends on prettier adding this configuration or seeing if they have some api that allows to change array configuration.
And per https://github.com/prettier/prettier/issues/4723, Prettier is decided to stay at do indent in mapping.
+1 for this, my dev teams preferred option is not to indent
+1 for this. :)
Also need this option
Another +1
Also an issue when using kustomize edit command (See https://github.com/kubernetes-sigs/kustomize/issues/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.
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.
Also an issue when using
kustomize editcommand
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.
Same issue here +1
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 https://github.com/prettier/prettier/pull/10927
Once/if the PR merges and releases we can just simply update prettier and enable the flag here. :slightly_smiling_face: 2. (https://github.com/redhat-developer/vscode-yaml/pull/519, https://github.com/redhat-developer/yaml-language-server/pull/471)
+1 for this.
@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 https://github.com/prettier/prettier/pull/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
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.
Same as above, wonder if there is any update here?
+1 for this. Most editors adds no indents for lists. Prettier breaks them without this option.
+1 please provide an option for me to config
The path forward is to extend prettierx and then use it instead of prettier?
https://github.com/brodybits/prettierx/issues/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.
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.
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 :)
@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.
Do we have any hope on resolving this any time soon? This makes the extension unusable for k8s-related development.
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
@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.
@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?
+1 on this one
now i find a new plugin:kubernetes-yaml-formatter https://github.com/longkai/kubernetes-yaml-formatter
+1
Was this issue addressed in the end?