private static void AnalyzeInitializer(SyntaxNodeAnalysisContext context) { var initializer = (InitializerExpressionSyntax)context.Node; SeparatedSyntaxList <ExpressionSyntax> expressions = initializer.Expressions; ExpressionSyntax first = expressions.FirstOrDefault(); if (first == null) { return; } if (IsExpectedTrailingTrivia(initializer.OpenBraceToken.TrailingTrivia)) { SyntaxTriviaList leading = first.GetLeadingTrivia(); if (leading.Any()) { TextSpan?span = GetEmptyLineSpan(leading, isEnd: false); if (span != null) { ReportDiagnostic(context, span.Value); } } } if (IsExpectedTrailingTrivia(expressions.GetTrailingTrivia())) { SyntaxTriviaList leading = initializer.CloseBraceToken.LeadingTrivia; if (leading.Any()) { TextSpan?span = GetEmptyLineSpan(leading, isEnd: true); if (span != null) { ReportDiagnostic(context, span.Value); } } }
private static void AnalyzeInitializer(SyntaxNodeAnalysisContext context) { var initializer = (InitializerExpressionSyntax)context.Node; SeparatedSyntaxList <ExpressionSyntax> expressions = initializer.Expressions; ExpressionSyntax first = expressions.FirstOrDefault(); if (first == null) { return; } if (IsExpectedTrailingTrivia(initializer.OpenBraceToken.TrailingTrivia)) { SyntaxTriviaList leading = first.GetLeadingTrivia(); if (leading.Any()) { TextSpan?span = GetEmptyLineSpan(leading, isEnd: false); if (span != null) { ReportDiagnostic(context, span.Value); } } } if (IsExpectedTrailingTrivia(expressions.GetTrailingTrivia())) { SyntaxTriviaList leading = initializer.CloseBraceToken.LeadingTrivia; if (leading.Any()) { TextSpan?span = GetEmptyLineSpan(leading, isEnd: true); if (span != null) { ReportDiagnostic(context, span.Value); } } } bool IsExpectedTrailingTrivia(SyntaxTriviaList triviaList) { foreach (SyntaxTrivia trivia in triviaList) { switch (trivia.Kind()) { case SyntaxKind.WhitespaceTrivia: break; case SyntaxKind.EndOfLineTrivia: return(true); default: return(false); } } return(false); } }