@@ -345,34 +345,48 @@ private static void HandleMemberList(SyntaxNodeAnalysisContext context, SyntaxLi
345345
346346 if ( ! members [ i - 1 ] . ContainsDiagnostics && ! members [ i ] . ContainsDiagnostics )
347347 {
348- // Report if
349- // the current declaration is not a field declaration
350- // or the previous declaration is of different type
351- // or the previous declaration spans across multiple lines
352- //
353- // Note that the order of checking is important, as the call to IsMultiLine requires a FieldDeclarationSyntax,
354- // something that can only be guaranteed if the first two checks fail.
355- if ( ! members [ i ] . IsKind ( SyntaxKind . FieldDeclaration )
356- || ! members [ i - 1 ] . IsKind ( members [ i ] . Kind ( ) )
357- || IsMultiline ( ( FieldDeclarationSyntax ) members [ i - 1 ] ) )
348+ // Don't report if
349+ // the previous declaration is of the same type
350+ // AND it is either
351+ // - a single line field declaration where the previous field is single line
352+ // or
353+ // - a single line property declaration where the previous property is single line
354+ if ( members [ i - 1 ] . IsKind ( members [ i ] . Kind ( ) )
355+ && ( ( members [ i ] . IsKind ( SyntaxKind . FieldDeclaration )
356+ && ! IsMultiline ( ( FieldDeclarationSyntax ) members [ i ] )
357+ && ! IsMultiline ( ( FieldDeclarationSyntax ) members [ i - 1 ] ) )
358+ || ( members [ i ] . IsKind ( SyntaxKind . PropertyDeclaration )
359+ && ! IsMultiline ( ( PropertyDeclarationSyntax ) members [ i ] )
360+ && ! IsMultiline ( ( PropertyDeclarationSyntax ) members [ i - 1 ] ) ) ) )
358361 {
359- ReportIfThereIsNoBlankLine ( context , members [ i - 1 ] , members [ i ] ) ;
362+ continue ;
360363 }
364+
365+ ReportIfThereIsNoBlankLine ( context , members [ i - 1 ] , members [ i ] ) ;
361366 }
362367 }
363368 }
364369
365370 private static bool IsMultiline ( FieldDeclarationSyntax fieldDeclaration )
366371 {
367- var lineSpan = fieldDeclaration . GetLineSpan ( ) ;
368- var attributeLists = fieldDeclaration . AttributeLists ;
372+ return IsMultiline ( fieldDeclaration , fieldDeclaration . AttributeLists ) ;
373+ }
374+
375+ private static bool IsMultiline ( PropertyDeclarationSyntax propertyDeclaration )
376+ {
377+ return IsMultiline ( propertyDeclaration , propertyDeclaration . AttributeLists ) ;
378+ }
379+
380+ private static bool IsMultiline ( MemberDeclarationSyntax memberDeclaration , SyntaxList < AttributeListSyntax > attributeLists )
381+ {
382+ var lineSpan = memberDeclaration . GetLineSpan ( ) ;
369383
370384 int startLine ;
371385
372386 // Exclude attributes when determining if a field declaration spans multiple lines
373387 if ( attributeLists . Count > 0 )
374388 {
375- var lastAttributeSpan = fieldDeclaration . SyntaxTree . GetLineSpan ( attributeLists . Last ( ) . FullSpan ) ;
389+ var lastAttributeSpan = memberDeclaration . SyntaxTree . GetLineSpan ( attributeLists . Last ( ) . FullSpan ) ;
376390 startLine = lastAttributeSpan . EndLinePosition . Line ;
377391 }
378392 else
0 commit comments