Skip to content

Commit

Permalink
Prevent reordered nodes from impacting blank line count
Browse files Browse the repository at this point in the history
  • Loading branch information
jgustie committed Nov 30, 2021
1 parent 3b5045f commit 178223b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/konjure/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ func (w *GroupWriter) indexNodes(nodes []*yaml.RNode) (map[string][]*yaml.RNode,
func restoreVerticalWhiteSpace(nodes []*yaml.RNode) {
for _, node := range nodes {
n := node.YNode()
minLL := n.Line
for i := range n.Content {
// No need to insert VWS if we are still on the same line
if i == 0 || n.Content[i].Line == n.Content[i-1].Line {
Expand All @@ -453,7 +454,10 @@ func restoreVerticalWhiteSpace(nodes []*yaml.RNode) {
}

// The previous node will have accounted for all the blanks above it
ll -= lastLine(n.Content[i-1])
if cll := lastLine(n.Content[i-1]); cll > minLL {
minLL = cll
}
ll -= minLL

// The foot comment will be stored two nodes back if this is a mapping node
footComment := n.Content[i-1].FootComment
Expand Down

0 comments on commit 178223b

Please sign in to comment.