mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-06 21:55:37 +00:00
Merge f53d561592 into e95bb7e472
This commit is contained in:
commit
6d89524dd8
@ -71,6 +71,29 @@ func deleteFromMap(node *CandidateNode, childPath interface{}) {
|
|||||||
node.Content = newContents
|
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{}) {
|
func deleteFromArray(node *CandidateNode, childPath interface{}) {
|
||||||
log.Debug("deleteFromArray")
|
log.Debug("deleteFromArray")
|
||||||
contents := node.Content
|
contents := node.Content
|
||||||
@ -87,4 +110,5 @@ func deleteFromArray(node *CandidateNode, childPath interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.Content = newContents
|
node.Content = newContents
|
||||||
|
normaliseEmptySequenceMapKeyComment(node)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,6 +119,19 @@ var deleteOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!map)::a: []\n",
|
"D0, P[], (!!map)::a: []\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "Delete all entries from list with inline key comment",
|
||||||
|
document: `testList: # A comment
|
||||||
|
- name: test1
|
||||||
|
value: 123
|
||||||
|
- name: test2
|
||||||
|
value: 456`,
|
||||||
|
expression: `del(.testList[])`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::testList: [] # A comment\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
description: "Delete entry appended to an array",
|
description: "Delete entry appended to an array",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user