diff --git a/src/Meziantou.Analyzer/Rules/AvoidUsingRedundantElseAnalyzer.cs b/src/Meziantou.Analyzer/Rules/AvoidUsingRedundantElseAnalyzer.cs index 09339d6f..f21f2bb1 100644 --- a/src/Meziantou.Analyzer/Rules/AvoidUsingRedundantElseAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/AvoidUsingRedundantElseAnalyzer.cs @@ -65,7 +65,7 @@ private static void AnalyzeElseClause(SyntaxNodeAnalysisContext context) if (controlFlowAnalysis is null || !controlFlowAnalysis.Succeeded) return; - if (!controlFlowAnalysis.EndPointIsReachable || controlFlowAnalysis.ExitPoints.Any(ep => IsDirectAccess(ifStatement, ep))) + if (!controlFlowAnalysis.EndPointIsReachable) { context.ReportDiagnostic(Rule, elseClause.ElseKeyword); } @@ -91,28 +91,4 @@ private static IEnumerable FindLocalIdentifiersIn(SyntaxNode node) } } } - - /// - /// Determines if a given 'if' statement's access to an exit point is straightforward. - /// For instance, access to an exit point in a nested 'if' would not be considered straightforward. - /// - /// The 'if' statement whose 'else' is currently under scrutiny - /// A reachable exit point detected by the semantic model - /// true if the exit point is directly accessible, false otherwise - private static bool IsDirectAccess(IfStatementSyntax ifStatementSyntax, SyntaxNode exitPoint) - { - var node = exitPoint.Parent; - while (node is not null) - { - if (node == ifStatementSyntax) - return true; - - if (!node.IsKind(SyntaxKind.Block)) - break; - - node = node.Parent; - } - - return false; - } }