google / google/yamlfmt

Incorrect comment movement for groups of array items

Open
#255 1 comment 0 reactions 0 assignees View on GitHub
yaml_v3_problem
Dominant language
Go
Stars
1.8k
Forks
75
PR merge metrics
No merged PRs in 30d

Description

I'd like to use comments to group sets of entries in an array together - the comment should be at the same level as the `-` for the entry; but yamlfmt keeps indenting or moving it, in consistent ways.

There also doesn't seem to be any docs saying what the expected indentation pattern is.

Testcase 1:
```
---
parent:
key:
- a: 1
b: 2

# Group comment
- &anchor
a: 2
b: 3
- a: 4
b: 5
```

Result 1:
```
$ yamlfmt -dry test1.yaml
test1.yaml:
--- ---
parent: parent:
key: key:
- a: 1 - a: 1
b: 2 b: 2
-
- # Group comment
- &anchor - &anchor
+ # Group comment
a: 2 a: 2
- b: 3 b: 3
- a: 4 - a: 4
- b: 5 b: 5
```

Testcase 2:
```
---
key:
#
- x: a
b: 1
- y: foo
b: bar
#

#
- z: ax
b: 1
- ab: something
b: 1
#
```

Result 2:
```
$ yamlfmt -dry test2.yaml
test2.yaml:
--- ---
key: key:
# #
- x: a - x: a
b: 1 b: 1
- y: foo - y: foo
b: bar b: bar
# #

# #
- z: ax - z: ax
b: 1 b: 1
- ab: something - ab: something
b: 1 b: 1
- # #
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.