Skip to content

Commit 4893a34

Browse files
authored
bugfix: false positive on expressions containing Count (#384)
* bugfix: false positive on expressions containing Count
1 parent 731954c commit 4893a34

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ public class CollectionTests
329329
[AssertionDiagnostic(@"var array = new string[1, 1]; array.Length.Should().Be(0{0});")]
330330
[AssertionDiagnostic(@"var array = new string[2, 2]; array.Length.Should().Be(0{0});")]
331331
[AssertionDiagnostic(@"var array = new string[3, 3, 3]; array.Length.Should().Be(0{0});")]
332+
[AssertionDiagnostic(@"int[] array1 = [1, 2, 3]; int[] array2 = [4, 5, 6]; int[] both = [..array1, ..array2]; (array1.Length + array2.Length).Should().Be(both.Length{0});")]
332333
[Implemented(Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/309")]
333334
public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(new StringBuilder()
334335
.AppendLine("using System;")

src/FluentAssertions.Analyzers/Tips/FluentAssertionsAnalyzer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
334334

335335
}
336336
}
337-
if (invocation.TryGetFirstDescendent<IPropertyReferenceOperation>(out var propertyBeforeShould))
337+
var argument = invocation.Arguments[0].Value.UnwrapConversion();
338+
if (argument is IPropertyReferenceOperation propertyBeforeShould)
338339
{
339340
switch (propertyBeforeShould.Property.Name)
340341
{

0 commit comments

Comments
 (0)