Skip to content

Commit d8cfa91

Browse files
Copilotstephentoub
andcommitted
Simplify code: merge recursive methods and remove irrelevant increment/decrement checks
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent ef6de95 commit d8cfa91

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/Microsoft.NetCore.Analyzers/Runtime/AvoidRedundantRegexIsMatchBeforeMatch.cs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,7 @@ private static bool IsRegexIsMatchCall(IOperation condition, ImmutableArray<IMet
8686
return false;
8787
}
8888

89-
private static bool FindMatchCallInBranch(IOperation branch, ImmutableArray<IMethodSymbol> regexMatchSymbols, IInvocationOperation isMatchCall, IOperation conditionalOperation, out IInvocationOperation matchCall)
90-
{
91-
// Search for the first Match call that matches criteria
92-
return FindMatchCallRecursive(branch, regexMatchSymbols, isMatchCall, conditionalOperation, out matchCall);
93-
}
94-
95-
private static bool FindMatchCallRecursive(IOperation operation, ImmutableArray<IMethodSymbol> regexMatchSymbols, IInvocationOperation isMatchCall, IOperation conditionalOperation, out IInvocationOperation matchCall)
89+
private static bool FindMatchCallInBranch(IOperation operation, ImmutableArray<IMethodSymbol> regexMatchSymbols, IInvocationOperation isMatchCall, IOperation conditionalOperation, out IInvocationOperation matchCall)
9690
{
9791
if (operation is IInvocationOperation invocation &&
9892
regexMatchSymbols.Contains(invocation.TargetMethod, SymbolEqualityComparer.Default))
@@ -107,7 +101,7 @@ private static bool FindMatchCallRecursive(IOperation operation, ImmutableArray<
107101

108102
foreach (var child in operation.Children)
109103
{
110-
if (FindMatchCallRecursive(child, regexMatchSymbols, isMatchCall, conditionalOperation, out matchCall))
104+
if (FindMatchCallInBranch(child, regexMatchSymbols, isMatchCall, conditionalOperation, out matchCall))
111105
{
112106
return true;
113107
}
@@ -261,7 +255,7 @@ private static bool HasAssignmentToSymbol(ISymbol symbol, IOperation operation)
261255
}
262256
}
263257

264-
// Check for compound assignments
258+
// Check for compound assignments (e.g., +=, -=, etc.)
265259
if (operation is ICompoundAssignmentOperation compoundAssignment)
266260
{
267261
if (compoundAssignment.Target is ILocalReferenceOperation compoundTargetLocal &&
@@ -276,21 +270,6 @@ private static bool HasAssignmentToSymbol(ISymbol symbol, IOperation operation)
276270
}
277271
}
278272

279-
// Check for increments/decrements
280-
if (operation is IIncrementOrDecrementOperation increment)
281-
{
282-
if (increment.Target is ILocalReferenceOperation incrementTargetLocal &&
283-
SymbolEqualityComparer.Default.Equals(incrementTargetLocal.Local, symbol))
284-
{
285-
return true;
286-
}
287-
if (increment.Target is IParameterReferenceOperation incrementTargetParam &&
288-
SymbolEqualityComparer.Default.Equals(incrementTargetParam.Parameter, symbol))
289-
{
290-
return true;
291-
}
292-
}
293-
294273
// Recursively check children
295274
foreach (var child in operation.Children)
296275
{

0 commit comments

Comments
 (0)