prettier: Yaml indentation duplicated at nested sequences
Prettier 1.16.4 Playground link
--parser yaml
Input:
---
a1:
- b: 2
c:
d: 2
e: 2
- f:
- f1: 4
- f2: 4
Output:
---
a1:
- b: 2
c:
d: 2
e: 2
- f:
- f1: 4
- f2: 4
Expected behavior:
Indentation of f1, f2 should be the same as the input.
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 12
- Comments: 18 (2 by maintainers)
I think prettier’s option philosophy should be revised, or perhaps reinterpreted.
Prettier’s intrinsic value is in its ability to impose some commonly held opinion on a code base, but it is misguided for prettier to attempt to impose a single, specific opinion on every code base, no matter how well crowd-sourced this opinion is. One single format is only viable in the few exceedingly rare languages like golang that were designed for a single format and rigorously enforce their format.
YAML on the other hand, for better or worse, has millions of adherents to two distinct styles. It is obstinate to support only one of these styles.
Just a note. VS Code suggests RedHat extension for YAML, which is the most popular. It is in turn uses prettier. That would mean that RedHat VS Code extension is also not for that audience… This is all too complicated…
@joebowbeer Prettier decided that if they ever added another option, then they would be forever barraged with various requests for all sorts of options. As a result, they can never admit that they should never have extended to encompass formatting YAML where there is not a definitive authority to set a single “opinionated” format. The prettier legacy options relieve the tension of a similar dilemma for JavaScript rather conveniently. Oh well.
Guys, what is the punchline? Can we have an option NOT to indent sequences? There is an issue on yaml-language-server about it - https://github.com/redhat-developer/yaml-language-server/issues/195
The proposal is to have something like
listTabWidth, but I think a boolean is enough -indentLists.Can we have it please, if you do not want to merge the PR that just removes the list indentation.
@Rikilele I agree with you. Working primarily with Kubernetes - which does not use indents in sequences - wired my brain to not use indents. I will just let it go.
~The YAML spec is in favor for the expected format: https://yaml.org~
Also other tools do not add an extra indent to lists: