Skip to content

Commit e3ba459

Browse files
committed
Simplify condition checks
1 parent 2aeb4e3 commit e3ba459

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1516ElementsMustBeSeparatedByBlankLine.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,25 @@ private static void HandleMemberList(SyntaxNodeAnalysisContext context, SyntaxLi
345345

346346
if (!members[i - 1].ContainsDiagnostics && !members[i].ContainsDiagnostics)
347347
{
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]))))
348+
// Report if
349+
// the current declaration is not a field declaration or property 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
354+
// FieldDeclarationSyntax or PropertyDeclarationSyntax, something that can only be guaranteed if the
355+
// first two checks fail.
356+
if (members[i].IsKind(SyntaxKind.FieldDeclaration)
357+
&& members[i - 1].IsKind(members[i].Kind())
358+
&& !IsMultiline((FieldDeclarationSyntax)members[i - 1]))
359+
{
360+
continue;
361+
}
362+
363+
if (members[i].IsKind(SyntaxKind.PropertyDeclaration)
364+
&& members[i - 1].IsKind(members[i].Kind())
365+
&& !IsMultiline((PropertyDeclarationSyntax)members[i])
366+
&& !IsMultiline((PropertyDeclarationSyntax)members[i - 1]))
361367
{
362368
continue;
363369
}

0 commit comments

Comments
 (0)