@@ -69,7 +69,7 @@ private static void AnalyzeInitializerExpression(SyntaxNodeAnalysisContext conte
6969 ReportRemove ( context , expressions . GetSeparator ( count - 1 ) ) ;
7070 }
7171 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
72- && expressions . IsSingleLine ( cancellationToken : context . CancellationToken ) )
72+ && initializer . IsSingleLine ( cancellationToken : context . CancellationToken ) )
7373 {
7474 ReportRemove ( context , expressions . GetSeparator ( count - 1 ) ) ;
7575 }
@@ -81,7 +81,7 @@ private static void AnalyzeInitializerExpression(SyntaxNodeAnalysisContext conte
8181 ReportAdd ( context , expressions . Last ( ) ) ;
8282 }
8383 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
84- && ! expressions . IsSingleLine ( cancellationToken : context . CancellationToken ) )
84+ && ! initializer . IsSingleLine ( cancellationToken : context . CancellationToken ) )
8585 {
8686 ReportAdd ( context , expressions . Last ( ) ) ;
8787 }
@@ -104,6 +104,7 @@ private static void AnalyzeEnumDeclaration(SyntaxNodeAnalysisContext context)
104104
105105 int count = members . Count ;
106106 int separatorCount = members . SeparatorCount ;
107+ TextSpan bracesSpan = TextSpan . FromBounds ( enumDeclaration . OpenBraceToken . SpanStart , enumDeclaration . CloseBraceToken . Span . End ) ;
107108
108109 if ( count == separatorCount )
109110 {
@@ -112,7 +113,7 @@ private static void AnalyzeEnumDeclaration(SyntaxNodeAnalysisContext context)
112113 ReportRemove ( context , members . GetSeparator ( count - 1 ) ) ;
113114 }
114115 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
115- && members . IsSingleLine ( cancellationToken : context . CancellationToken ) )
116+ && bracesSpan . IsSingleLine ( enumDeclaration . SyntaxTree , cancellationToken : context . CancellationToken ) )
116117 {
117118 ReportRemove ( context , members . GetSeparator ( count - 1 ) ) ;
118119 }
@@ -124,7 +125,7 @@ private static void AnalyzeEnumDeclaration(SyntaxNodeAnalysisContext context)
124125 ReportAdd ( context , members . Last ( ) ) ;
125126 }
126127 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
127- && ! members . IsSingleLine ( cancellationToken : context . CancellationToken ) )
128+ && ! bracesSpan . IsSingleLine ( enumDeclaration . SyntaxTree , cancellationToken : context . CancellationToken ) )
128129 {
129130 ReportAdd ( context , members . Last ( ) ) ;
130131 }
@@ -147,6 +148,7 @@ private static void AnalyzeAnonymousObjectCreationExpression(SyntaxNodeAnalysisC
147148
148149 int count = initializers . Count ;
149150 int separatorCount = initializers . SeparatorCount ;
151+ TextSpan bracesSpan = TextSpan . FromBounds ( objectCreation . OpenBraceToken . SpanStart , objectCreation . CloseBraceToken . Span . End ) ;
150152
151153 if ( count == separatorCount )
152154 {
@@ -155,7 +157,7 @@ private static void AnalyzeAnonymousObjectCreationExpression(SyntaxNodeAnalysisC
155157 ReportRemove ( context , initializers . GetSeparator ( count - 1 ) ) ;
156158 }
157159 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
158- && initializers . IsSingleLine ( cancellationToken : context . CancellationToken ) )
160+ && bracesSpan . IsSingleLine ( objectCreation . SyntaxTree , cancellationToken : context . CancellationToken ) )
159161 {
160162 ReportRemove ( context , initializers . GetSeparator ( count - 1 ) ) ;
161163 }
@@ -167,7 +169,7 @@ private static void AnalyzeAnonymousObjectCreationExpression(SyntaxNodeAnalysisC
167169 ReportAdd ( context , initializers . Last ( ) ) ;
168170 }
169171 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
170- && ! initializers . IsSingleLine ( cancellationToken : context . CancellationToken ) )
172+ && ! bracesSpan . IsSingleLine ( objectCreation . SyntaxTree , cancellationToken : context . CancellationToken ) )
171173 {
172174 ReportAdd ( context , initializers . Last ( ) ) ;
173175 }
@@ -181,15 +183,16 @@ private static void AnalyzeSwitchExpression(SyntaxNodeAnalysisContext context)
181183 if ( style == TrailingCommaStyle . None )
182184 return ;
183185
184- var objectCreation = ( SwitchExpressionSyntax ) context . Node ;
186+ var switchExpression = ( SwitchExpressionSyntax ) context . Node ;
185187
186- SeparatedSyntaxList < SwitchExpressionArmSyntax > arms = objectCreation . Arms ;
188+ SeparatedSyntaxList < SwitchExpressionArmSyntax > arms = switchExpression . Arms ;
187189
188190 if ( ! arms . Any ( ) )
189191 return ;
190192
191193 int count = arms . Count ;
192194 int separatorCount = arms . SeparatorCount ;
195+ TextSpan bracesSpan = TextSpan . FromBounds ( switchExpression . OpenBraceToken . SpanStart , switchExpression . CloseBraceToken . Span . End ) ;
193196
194197 if ( count == separatorCount )
195198 {
@@ -198,7 +201,7 @@ private static void AnalyzeSwitchExpression(SyntaxNodeAnalysisContext context)
198201 ReportRemove ( context , arms . GetSeparator ( count - 1 ) ) ;
199202 }
200203 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
201- && arms . IsSingleLine ( cancellationToken : context . CancellationToken ) )
204+ && bracesSpan . IsSingleLine ( switchExpression . SyntaxTree , cancellationToken : context . CancellationToken ) )
202205 {
203206 ReportRemove ( context , arms . GetSeparator ( count - 1 ) ) ;
204207 }
@@ -210,7 +213,7 @@ private static void AnalyzeSwitchExpression(SyntaxNodeAnalysisContext context)
210213 ReportAdd ( context , arms . Last ( ) ) ;
211214 }
212215 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
213- && ! arms . IsSingleLine ( cancellationToken : context . CancellationToken ) )
216+ && ! bracesSpan . IsSingleLine ( switchExpression . SyntaxTree , cancellationToken : context . CancellationToken ) )
214217 {
215218 ReportAdd ( context , arms . Last ( ) ) ;
216219 }
@@ -224,15 +227,16 @@ private static void AnalyzePropertyPatternClause(SyntaxNodeAnalysisContext conte
224227 if ( style == TrailingCommaStyle . None )
225228 return ;
226229
227- var objectCreation = ( PropertyPatternClauseSyntax ) context . Node ;
230+ var patternClause = ( PropertyPatternClauseSyntax ) context . Node ;
228231
229- SeparatedSyntaxList < SubpatternSyntax > subpatterns = objectCreation . Subpatterns ;
232+ SeparatedSyntaxList < SubpatternSyntax > subpatterns = patternClause . Subpatterns ;
230233
231234 if ( ! subpatterns . Any ( ) )
232235 return ;
233236
234237 int count = subpatterns . Count ;
235238 int separatorCount = subpatterns . SeparatorCount ;
239+ TextSpan bracesSpan = TextSpan . FromBounds ( patternClause . OpenBraceToken . SpanStart , patternClause . CloseBraceToken . Span . End ) ;
236240
237241 if ( count == separatorCount )
238242 {
@@ -241,7 +245,7 @@ private static void AnalyzePropertyPatternClause(SyntaxNodeAnalysisContext conte
241245 ReportRemove ( context , subpatterns . GetSeparator ( count - 1 ) ) ;
242246 }
243247 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
244- && subpatterns . IsSingleLine ( cancellationToken : context . CancellationToken ) )
248+ && bracesSpan . IsSingleLine ( patternClause . SyntaxTree , cancellationToken : context . CancellationToken ) )
245249 {
246250 ReportRemove ( context , subpatterns . GetSeparator ( count - 1 ) ) ;
247251 }
@@ -253,7 +257,7 @@ private static void AnalyzePropertyPatternClause(SyntaxNodeAnalysisContext conte
253257 ReportAdd ( context , subpatterns . Last ( ) ) ;
254258 }
255259 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
256- && ! subpatterns . IsSingleLine ( cancellationToken : context . CancellationToken ) )
260+ && ! bracesSpan . IsSingleLine ( patternClause . SyntaxTree , cancellationToken : context . CancellationToken ) )
257261 {
258262 ReportAdd ( context , subpatterns . Last ( ) ) ;
259263 }
@@ -268,15 +272,16 @@ private static void AnalyzeCollectionExpression(SyntaxNodeAnalysisContext contex
268272 if ( style == TrailingCommaStyle . None )
269273 return ;
270274
271- var objectCreation = ( CollectionExpressionSyntax ) context . Node ;
275+ var collectionExpression = ( CollectionExpressionSyntax ) context . Node ;
272276
273- SeparatedSyntaxList < CollectionElementSyntax > elements = objectCreation . Elements ;
277+ SeparatedSyntaxList < CollectionElementSyntax > elements = collectionExpression . Elements ;
274278
275279 if ( ! elements . Any ( ) )
276280 return ;
277281
278282 int count = elements . Count ;
279283 int separatorCount = elements . SeparatorCount ;
284+ TextSpan bracesSpan = TextSpan . FromBounds ( collectionExpression . OpenBracketToken . SpanStart , collectionExpression . CloseBracketToken . Span . End ) ;
280285
281286 if ( count == separatorCount )
282287 {
@@ -285,7 +290,7 @@ private static void AnalyzeCollectionExpression(SyntaxNodeAnalysisContext contex
285290 ReportRemove ( context , elements . GetSeparator ( count - 1 ) ) ;
286291 }
287292 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
288- && elements . IsSingleLine ( cancellationToken : context . CancellationToken ) )
293+ && bracesSpan . IsSingleLine ( collectionExpression . SyntaxTree , cancellationToken : context . CancellationToken ) )
289294 {
290295 ReportRemove ( context , elements . GetSeparator ( count - 1 ) ) ;
291296 }
@@ -297,7 +302,7 @@ private static void AnalyzeCollectionExpression(SyntaxNodeAnalysisContext contex
297302 ReportAdd ( context , elements . Last ( ) ) ;
298303 }
299304 else if ( style == TrailingCommaStyle . OmitWhenSingleLine
300- && ! elements . IsSingleLine ( cancellationToken : context . CancellationToken ) )
305+ && ! bracesSpan . IsSingleLine ( collectionExpression . SyntaxTree , cancellationToken : context . CancellationToken ) )
301306 {
302307 ReportAdd ( context , elements . Last ( ) ) ;
303308 }
0 commit comments