private Diagnostic HandleMethod(MethodDeclarationSyntax methodDeclaration) { if (methodDeclaration.ExpressionBody != null) { return(null); } if (methodDeclaration.DescendantNodesAndTokensAndSelf().Any(x => x.GetLeadingTrivia().Concat(x.GetTrailingTrivia()).Any(y => !y.IsWhitespaceTrivia()))) { return(null); } if (methodDeclaration.Body?.Statements.Count != 1) { return(null); } var statement = methodDeclaration.Body.Statements.FirstOrDefault(); var returnStatement = statement?.DescendantNodesAndSelf().OfType <ReturnStatementSyntax>().FirstOrDefault(); if (returnStatement == null) { return(null); } return(Diagnostic.Create(Rule, returnStatement.GetLocation(), "Method", methodDeclaration.Identifier.ValueText)); }
private Diagnostic HandleMethod(MethodDeclarationSyntax methodDeclaration) { if (methodDeclaration.ExpressionBody != null) { return(null); } if ( methodDeclaration.DescendantNodesAndTokensAndSelf() .Any(x => x.GetLeadingTrivia().Concat(x.GetTrailingTrivia()).Any(y => !y.IsWhitespaceTrivia()))) { return(null); } if (methodDeclaration.Body?.Statements.Count != 1) { return(null); } if (!Nodes.Contains(methodDeclaration.Body.Statements[0].Kind())) { return(null); } return(Diagnostic.Create(Rule, methodDeclaration.Identifier.GetLocation(), "Method", methodDeclaration.Identifier.ValueText)); }