Auto style when adding to empty maps/arrays

This commit is contained in:
Mike Farah
2022-01-27 09:58:13 +11:00
parent 71242b0c8e
commit c3d815998a
4 changed files with 83 additions and 4 deletions
+4 -1
View File
@@ -150,7 +150,10 @@ func (n *CandidateNode) UpdateAttributesFrom(other *CandidateNode, prefs assignP
// merge will pickup the style of the new thing
// when autocreating nodes
if n.Node.Style == 0 {
//
// if this is an empty map or empty array, use the style of other node.
if n.Node.Style == 0 || (n.Node.Kind != yaml.ScalarNode && len(n.Node.Content) == 0) {
n.Node.Style = other.Node.Style
}