Skip to content

Commit e195b78

Browse files
Copilotmeziantou
andcommitted
Address code review feedback: use else-if and clarify variable naming
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
1 parent 92cf7c5 commit e195b78

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/Meziantou.Analyzer.CodeFixers/Rules/UseAttributeIsDefinedFixer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ private static async Task<Document> ReplaceWithAttributeIsDefined(Document docum
7575
else
7676
{
7777
// Check for GetCustomAttributes().Count() comparisons
78-
var countInvocation = GetGetCustomAttributesCountInvocation(binaryOperation.LeftOperand, out isLeftSide);
78+
var countInvocation = GetGetCustomAttributesCountInvocation(binaryOperation.LeftOperand, out var countIsOnLeft);
7979
if (countInvocation is null)
8080
{
81-
countInvocation = GetGetCustomAttributesCountInvocation(binaryOperation.RightOperand, out isLeftSide);
82-
isLeftSide = !isLeftSide; // If found on right, flip the comparison perspective
81+
countInvocation = GetGetCustomAttributesCountInvocation(binaryOperation.RightOperand, out var countIsOnRight);
82+
countIsOnLeft = !countIsOnRight; // If found on right, Count is not on left
8383
}
8484

8585
if (countInvocation is not null)
8686
{
87-
var negateCount = ShouldNegateLengthComparison(binaryOperation, isLeftSide);
87+
var negateCount = ShouldNegateLengthComparison(binaryOperation, countIsOnLeft);
8888
replacement = CreateAttributeIsDefinedInvocation(generator, semanticModel, countInvocation, negateCount);
8989
}
9090
}

src/Meziantou.Analyzer/Rules/UseAttributeIsDefinedAnalyzer.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ public void AnalyzeBinary(OperationAnalysisContext context)
7676
IsGetCustomAttributesLengthComparison(operation, operation.RightOperand, operation.LeftOperand, out _))
7777
{
7878
context.ReportDiagnostic(Rule, operation, "GetCustomAttributes().Length");
79-
return;
8079
}
81-
82-
if (IsGetCustomAttributesCountComparison(operation, operation.LeftOperand, operation.RightOperand, out _) ||
83-
IsGetCustomAttributesCountComparison(operation, operation.RightOperand, operation.LeftOperand, out _))
80+
else if (IsGetCustomAttributesCountComparison(operation, operation.LeftOperand, operation.RightOperand, out _) ||
81+
IsGetCustomAttributesCountComparison(operation, operation.RightOperand, operation.LeftOperand, out _))
8482
{
8583
context.ReportDiagnostic(Rule, operation, "GetCustomAttributes().Count()");
8684
}

0 commit comments

Comments
 (0)