feat(config): use block style for YAML maps/lists
Unified · Split
| @@ -326,6 +326,7 @@ func SaveConfigPreserveComments(configFile string, cfg *Config) error { · 325 unmodified lines | ||
| 326 | 326 | |
| 327 | 327 | // Merge generated into original in-place, preserving comments/order of existing nodes. |
| 328 | 328 | mergeMappingPreserve(original.Content[0], generated.Content[0]) |
| 329 | + normalizeCollectionNodeStyles(original.Content[0]) | |
| 329 | 330 | |
| 330 | 331 | // Write back. |
| 331 | 332 | f, err := os.Create(configFile) |
| @@ -566,3 +567,30 @@ func removeMapKey(mapNode *yaml.Node, key string) { · 234 unmodified lines | ||
| 566 | 567 | } |
| 567 | 568 | } |
| 568 | 569 | } |
| 570 | + | |
| 571 | +// normalizeCollectionNodeStyles forces YAML collections to use block notation, keeping | |
| 572 | +// lists and maps readable. Empty sequences retain flow style ([]) so empty list markers | |
| 573 | +// remain compact. | |
| 574 | +func normalizeCollectionNodeStyles(node *yaml.Node) { | |
| 575 | + if node == nil { | |
| 576 | + return | |
| 577 | + } | |
| 578 | + switch node.Kind { | |
| 579 | + case yaml.MappingNode: | |
| 580 | + node.Style = 0 | |
| 581 | + for i := range node.Content { | |
| 582 | + normalizeCollectionNodeStyles(node.Content[i]) | |
| 583 | + } | |
| 584 | + case yaml.SequenceNode: | |
| 585 | + if len(node.Content) == 0 { | |
| 586 | + node.Style = yaml.FlowStyle | |
| 587 | + } else { | |
| 588 | + node.Style = 0 | |
| 589 | + } | |
| 590 | + for i := range node.Content { | |
| 591 | + normalizeCollectionNodeStyles(node.Content[i]) | |
| 592 | + } | |
| 593 | + default: | |
| 594 | + // Scalars keep their existing style to preserve quoting | |
| 595 | + } | |
| 596 | +} | |