Fix deleting commented empty list YAML output (#2765)

This commit is contained in:
Dustin Persek
2026-08-03 13:20:19 +10:00
committed by GitHub
parent 2fbc2eab20
commit b74aefd55f
2 changed files with 37 additions and 0 deletions
+24
View File
@@ -71,6 +71,29 @@ func deleteFromMap(node *CandidateNode, childPath interface{}) {
node.Content = newContents
}
func normaliseEmptySequenceMapKeyComment(node *CandidateNode) {
if node.Kind != SequenceNode || len(node.Content) != 0 || node.LineComment != "" {
return
}
key := node.Key
if node.Parent != nil && node.Parent.Kind == MappingNode {
for index := 0; index < len(node.Parent.Content)-1; index += 2 {
if node.Parent.Content[index+1] == node {
key = node.Parent.Content[index]
break
}
}
}
if key == nil || key.LineComment == "" {
return
}
node.LineComment = key.LineComment
key.LineComment = ""
node.Style = FlowStyle
}
func deleteFromArray(node *CandidateNode, childPath interface{}) {
log.Debug("deleteFromArray")
contents := node.Content
@@ -87,4 +110,5 @@ func deleteFromArray(node *CandidateNode, childPath interface{}) {
}
}
node.Content = newContents
normaliseEmptySequenceMapKeyComment(node)
}