File tree 1 file changed +12
-3
lines changed
CodeGeneration/Sources/Utils
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -158,21 +158,30 @@ public class CodeGenerationFormat: BasicFormat {
158
158
}
159
159
formattedChildren = formattedChildren. map { child in
160
160
var child = child
161
- child. trailingTrivia = Trivia ( pieces: child. trailingTrivia. drop ( while: \. isSpaceOrTab) )
161
+
162
+ if let firstNonSpaceOrTabIndex = child. trailingTrivia. firstIndex ( where: { !$0. isSpaceOrTab } ) {
163
+ if child. trailingTrivia [ firstNonSpaceOrTabIndex] . isNewline {
164
+ child. trailingTrivia = Trivia ( pieces: child. trailingTrivia. suffix ( from: firstNonSpaceOrTabIndex) )
165
+ }
166
+ } else {
167
+ child. trailingTrivia = Trivia ( )
168
+ }
162
169
163
170
if !child. startsOnNewline {
164
171
child. leadingTrivia = indentedNewline + child. leadingTrivia
165
172
}
166
173
return child
167
174
}
168
175
decreaseIndentationLevel ( )
169
- if let lastChild = formattedChildren. last {
176
+ if let lastChild = formattedChildren. last,
177
+ !lastChild. trailingTrivia. contains ( where: \. isNewline)
178
+ {
170
179
let nextTokenStartsWithNewline =
171
180
lastChild. nextToken ( viewMode: . sourceAccurate) ? . leadingTrivia. first? . isNewline ?? false
172
181
if !nextTokenStartsWithNewline {
173
182
formattedChildren [ formattedChildren. count - 1 ] = lastChild. with (
174
183
\. trailingTrivia,
175
- indentedNewline
184
+ lastChild . trailingTrivia + indentedNewline
176
185
)
177
186
}
178
187
}
You can’t perform that action at this time.
0 commit comments