private static void AnalyzeDoStatement(SyntaxNodeAnalysisContext context) { var doStatement = (DoStatementSyntax)context.Node; StatementSyntax statement = doStatement.Statement; if (!statement.IsKind(SyntaxKind.Block)) { return; } NewLineStyle newLineStyle = context.GetNewLineBeforeWhileInDoStatement(); if (newLineStyle == NewLineStyle.None) { return; } SyntaxTriviaList trailingTrivia = statement.GetTrailingTrivia(); if (!trailingTrivia.Any() || trailingTrivia.SingleOrDefault(shouldThrow: false).IsWhitespaceTrivia()) { if (!doStatement.WhileKeyword.LeadingTrivia.Any() && newLineStyle == NewLineStyle.Add) { context.ReportDiagnostic( DiagnosticRules.AddOrRemoveNewLineBeforeWhileInDoStatement, Location.Create(doStatement.SyntaxTree, new TextSpan(statement.FullSpan.End, 0)), "Add"); } } else if (SyntaxTriviaAnalysis.IsOptionalWhitespaceThenEndOfLineTrivia(trailingTrivia)) { if (doStatement.WhileKeyword.LeadingTrivia.IsEmptyOrWhitespace() && newLineStyle == NewLineStyle.Remove) { context.ReportDiagnostic( DiagnosticRules.AddOrRemoveNewLineBeforeWhileInDoStatement, Location.Create(doStatement.SyntaxTree, new TextSpan(trailingTrivia.Last().SpanStart, 0)), properties: DiagnosticProperties.AnalyzerOption_Invert, "Remove"); } } }
private static void AnalyzeDoStatement(SyntaxNodeAnalysisContext context) { var doStatement = (DoStatementSyntax)context.Node; StatementSyntax statement = doStatement.Statement; if (!statement.IsKind(SyntaxKind.Block)) { return; } SyntaxTriviaList trailingTrivia = statement.GetTrailingTrivia(); if (!trailingTrivia.Any() || trailingTrivia.SingleOrDefault(shouldThrow: false).IsWhitespaceTrivia()) { if (!doStatement.WhileKeyword.LeadingTrivia.Any() && !AnalyzerOptions.RemoveNewLineBetweenClosingBraceAndWhileKeyword.IsEnabled(context)) { context.ReportDiagnostic( DiagnosticRules.AddNewLineBetweenClosingBraceAndWhileKeywordOrViceVersa, Location.Create(doStatement.SyntaxTree, new TextSpan(statement.FullSpan.End, 0)), AnalyzerOptions.RemoveNewLineBetweenClosingBraceAndWhileKeyword); } } else if (SyntaxTriviaAnalysis.IsOptionalWhitespaceThenEndOfLineTrivia(trailingTrivia)) { if (doStatement.WhileKeyword.LeadingTrivia.IsEmptyOrWhitespace() && AnalyzerOptions.RemoveNewLineBetweenClosingBraceAndWhileKeyword.IsEnabled(context)) { context.ReportDiagnostic( DiagnosticRules.ReportOnly.RemoveNewLineBetweenClosingBraceAndWhileKeyword, Location.Create(doStatement.SyntaxTree, new TextSpan(trailingTrivia.Last().SpanStart, 0)), properties: DiagnosticProperties.AnalyzerOption_Invert, AnalyzerOptions.RemoveNewLineBetweenClosingBraceAndWhileKeyword); } } }