Skip to content

Commit 7c4f03a

Browse files
committed
Fix CodeGenerationFormat to keep existing trailing trivia when adding a newline after the last element of a list
1 parent ac4a1f2 commit 7c4f03a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CodeGeneration/Sources/Utils/CodeGenerationFormat.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ public class CodeGenerationFormat: BasicFormat {
173173
return child
174174
}
175175
decreaseIndentationLevel()
176-
if let lastChild = formattedChildren.last {
176+
if let lastChild = formattedChildren.last,
177+
!lastChild.trailingTrivia.contains(where: \.isNewline)
178+
{
177179
let nextTokenStartsWithNewline =
178180
lastChild.nextToken(viewMode: .sourceAccurate)?.leadingTrivia.first?.isNewline ?? false
179181
if !nextTokenStartsWithNewline {
180182
formattedChildren[formattedChildren.count - 1] = lastChild.with(
181183
\.trailingTrivia,
182-
indentedNewline
184+
lastChild.trailingTrivia + indentedNewline
183185
)
184186
}
185187
}

0 commit comments

Comments
 (0)