Skip to content

Commit d5be4e5

Browse files
committed
Fix CodeGenerationFormat.formatChildrenSeparatedByNewline() to not add an extra newline to the end of a list that already has one
1 parent cdff432 commit d5be4e5

12 files changed

+8
-645
lines changed

CodeGeneration/Sources/Utils/CodeGenerationFormat.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,14 @@ public class CodeGenerationFormat: BasicFormat {
136136
}
137137
}
138138
decreaseIndentationLevel()
139-
if !formattedChildren.isEmpty {
140-
formattedChildren[formattedChildren.count - 1] = formattedChildren[formattedChildren.count - 1].with(
141-
\.trailingTrivia,
142-
indentedNewline
143-
)
139+
if let lastChild = formattedChildren.last {
140+
let nextTokenStartsWithNewline = lastChild.nextToken(viewMode: .all)?.leadingTrivia.first?.isNewline ?? false
141+
if !nextTokenStartsWithNewline {
142+
formattedChildren[formattedChildren.count - 1] = lastChild.with(
143+
\.trailingTrivia,
144+
indentedNewline
145+
)
146+
}
144147
}
145148
return formattedChildren
146149
}

0 commit comments

Comments
 (0)