@@ -99,10 +99,7 @@ public class CodeGenerationFormat: BasicFormat {
99
99
let inMethodCallThatStartsOnNewline =
100
100
if let functionCallExpr = node. parent? . as ( FunctionCallExprSyntax . self) ,
101
101
let memberAccessExpr = functionCallExpr. calledExpression. as ( MemberAccessExprSyntax . self) ,
102
- memberAccessExpr. period. leadingTrivia. contains ( where: \. isNewline)
103
- || memberAccessExpr. period. previousToken ( viewMode: . sourceAccurate) ? . trailingTrivia. contains (
104
- where: \. isNewline
105
- ) ?? false
102
+ startsOnNewline ( memberAccessExpr. period)
106
103
{
107
104
true
108
105
} else {
@@ -132,10 +129,7 @@ public class CodeGenerationFormat: BasicFormat {
132
129
if indentManually {
133
130
return false
134
131
}
135
- let startsOnNewline =
136
- node. leadingTrivia. contains ( where: \. isNewline)
137
- || node. previousToken ( viewMode: . sourceAccurate) ? . trailingTrivia. contains ( where: \. isNewline) ?? false
138
- if !startsOnNewline {
132
+ if !startsOnNewline( node) {
139
133
return false
140
134
}
141
135
default :
@@ -172,11 +166,7 @@ public class CodeGenerationFormat: BasicFormat {
172
166
var child = child
173
167
child. trailingTrivia = Trivia ( pieces: child. trailingTrivia. drop ( while: \. isSpaceOrTab) )
174
168
175
- let startsOnNewline =
176
- child. leadingTrivia. contains ( where: \. isNewline)
177
- || child. previousToken ( viewMode: . sourceAccurate) ? . trailingTrivia. contains ( where: \. isNewline) ?? false
178
-
179
- if !startsOnNewline {
169
+ if !startsOnNewline( child) {
180
170
child. leadingTrivia = indentedNewline + child. leadingTrivia
181
171
}
182
172
return child
@@ -195,3 +185,8 @@ public class CodeGenerationFormat: BasicFormat {
195
185
return formattedChildren
196
186
}
197
187
}
188
+
189
+ private func startsOnNewline( _ node: some SyntaxProtocol ) -> Bool {
190
+ return node. leadingTrivia. contains ( where: \. isNewline)
191
+ || node. previousToken ( viewMode: . sourceAccurate) ? . trailingTrivia. contains ( where: \. isNewline) ?? false
192
+ }
0 commit comments