@@ -61,11 +61,8 @@ public class SA1117ParametersMustBeOnSameLineOrSeparateLines : DiagnosticAnalyze
6161 private static readonly DiagnosticDescriptor Descriptor =
6262 new DiagnosticDescriptor ( DiagnosticId , Title , MessageFormat , AnalyzerCategory . ReadabilityRules , DiagnosticSeverity . Warning , AnalyzerConstants . EnabledByDefault , Description , HelpLink ) ;
6363
64- private static readonly ImmutableArray < DiagnosticDescriptor > SupportedDiagnosticsValue =
65- ImmutableArray . Create ( Descriptor ) ;
66-
6764 /// <inheritdoc/>
68- public override ImmutableArray < DiagnosticDescriptor > SupportedDiagnostics => SupportedDiagnosticsValue ;
65+ public override ImmutableArray < DiagnosticDescriptor > SupportedDiagnostics { get ; } = ImmutableArray . Create ( Descriptor ) ;
6966
7067 /// <inheritdoc/>
7168 public override void Initialize ( AnalysisContext context )
@@ -151,17 +148,12 @@ private static void HandleArrayCreation(SyntaxNodeAnalysisContext context)
151148 if ( firstParameterLine == previousLine )
152149 {
153150 // arguments must be on same line
154- lineCondition = ( param1Line , param2Line ) => param1Line != param2Line ;
155- }
156- else if ( previousLine - firstParameterLine == 1 )
157- {
158- // each argument must be on its own line
159151 lineCondition = ( param1Line , param2Line ) => param1Line == param2Line ;
160152 }
161153 else
162154 {
163- // SA1115 should be handled first
164- return ;
155+ // each argument must be on its own line
156+ lineCondition = ( param1Line , param2Line ) => param1Line != param2Line ;
165157 }
166158
167159 for ( int i = 2 ; i < sizes . Count ; ++ i )
@@ -171,11 +163,12 @@ private static void HandleArrayCreation(SyntaxNodeAnalysisContext context)
171163
172164 if ( lineCondition ( previousLine , currentLine ) )
173165 {
174- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , currentParameter . GetLocation ( ) ) ) ;
175- return ;
166+ previousLine = currentLine ;
167+ continue ;
176168 }
177169
178- previousLine = currentLine ;
170+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , currentParameter . GetLocation ( ) ) ) ;
171+ return ;
179172 }
180173 }
181174 }
@@ -203,17 +196,12 @@ private static void HandleAttribute(SyntaxNodeAnalysisContext context)
203196 if ( firstParameterLine == previousLine )
204197 {
205198 // arguments must be on same line
206- lineCondition = ( param1Line , param2Line ) => param1Line != param2Line ;
207- }
208- else if ( previousLine - firstParameterLine == 1 )
209- {
210- // each argument must be on its own line
211199 lineCondition = ( param1Line , param2Line ) => param1Line == param2Line ;
212200 }
213201 else
214202 {
215- // SA1115 should be handled first
216- return ;
203+ // each argument must be on its own line
204+ lineCondition = ( param1Line , param2Line ) => param1Line != param2Line ;
217205 }
218206
219207 for ( int i = 2 ; i < arguments . Count ; ++ i )
@@ -223,11 +211,12 @@ private static void HandleAttribute(SyntaxNodeAnalysisContext context)
223211
224212 if ( lineCondition ( previousLine , currentLine ) )
225213 {
226- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , currentParameter . GetLocation ( ) ) ) ;
227- return ;
214+ previousLine = currentLine ;
215+ continue ;
228216 }
229217
230- previousLine = currentLine ;
218+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , currentParameter . GetLocation ( ) ) ) ;
219+ return ;
231220 }
232221 }
233222
@@ -308,17 +297,12 @@ private static void Analyze(SyntaxNodeAnalysisContext context, SeparatedSyntaxLi
308297 if ( firstParameterLine == previousLine )
309298 {
310299 // parameters must be on same line
311- lineCondition = ( param1Line , param2Line ) => param1Line != param2Line ;
312- }
313- else if ( previousLine - firstParameterLine == 1 )
314- {
315- // each parameter must be on its own line
316300 lineCondition = ( param1Line , param2Line ) => param1Line == param2Line ;
317301 }
318302 else
319303 {
320- // SA1115 should be handled first
321- return ;
304+ // each parameter must be on its own line
305+ lineCondition = ( param1Line , param2Line ) => param1Line != param2Line ;
322306 }
323307
324308 for ( int i = 2 ; i < parameters . Count ; ++ i )
@@ -328,11 +312,12 @@ private static void Analyze(SyntaxNodeAnalysisContext context, SeparatedSyntaxLi
328312
329313 if ( lineCondition ( previousLine , currentLine ) )
330314 {
331- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , currentParameter . GetLocation ( ) ) ) ;
332- return ;
315+ previousLine = currentLine ;
316+ continue ;
333317 }
334318
335- previousLine = currentLine ;
319+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , currentParameter . GetLocation ( ) ) ) ;
320+ return ;
336321 }
337322 }
338323
@@ -346,17 +331,12 @@ private static void Analyze(SyntaxNodeAnalysisContext context, SeparatedSyntaxLi
346331 if ( firstParameterLine == previousLine )
347332 {
348333 // arguments must be on same line
349- lineCondition = ( param1Line , param2Line ) => param1Line != param2Line ;
350- }
351- else if ( previousLine - firstParameterLine == 1 )
352- {
353- // each argument must be on its own line
354334 lineCondition = ( param1Line , param2Line ) => param1Line == param2Line ;
355335 }
356336 else
357337 {
358- // SA1115 should be handled first
359- return ;
338+ // each argument must be on its own line
339+ lineCondition = ( param1Line , param2Line ) => param1Line != param2Line ;
360340 }
361341
362342 for ( int i = 2 ; i < arguments . Count ; ++ i )
@@ -366,11 +346,12 @@ private static void Analyze(SyntaxNodeAnalysisContext context, SeparatedSyntaxLi
366346
367347 if ( lineCondition ( previousLine , currentLine ) )
368348 {
369- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , currentParameter . GetLocation ( ) ) ) ;
370- return ;
349+ previousLine = currentLine ;
350+ continue ;
371351 }
372352
373- previousLine = currentLine ;
353+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , currentParameter . GetLocation ( ) ) ) ;
354+ return ;
374355 }
375356 }
376357 }
0 commit comments