Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix issue 290 #292

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,62 @@ public class MyCollectionType { }";
})
);
}

[TestMethod]
[Implemented(Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/290")]
public void ShouldNotReportIssue290()
{
const string source = @"
using FluentAssertions;
using FluentAssertions.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
public class TestClass
{
public static void Main()
{
IEnumerable<Item> expectedOrderedNames = new[] { new Item(""Alpha""), new Item(""Bravo""), new Item(""Charlie"") };
IEnumerable<Parent> actual = GetSortedItems();

actual.Select(x => x.Item).Should().Equal(expectedOrderedNames);
}

static IEnumerable<Parent> GetSortedItems()
{
yield return new Parent(""Bravo"");
yield return new Parent(""Charlie"");
yield return new Parent(""Alpha"");
}
}

public class Item
{
public string Name { get; set; }
public Guid Id { get; set; }

public Item(string name)
{
Name = name;
Id = Guid.NewGuid();
}
}

public class Parent
{
public Item Item { get; set; }

public Parent(string name)
{
Item = new Item(name);
}
}";

DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments()
.WithSources(source)
.WithAllAnalyzers()
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
);
}
}
}
2 changes: 1 addition & 1 deletion src/FluentAssertions.Analyzers/Tips/DiagnosticMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private DiagnosticMetadata(string message, string helpLink, [CallerMemberName] s
public static DiagnosticMetadata CollectionShouldHaveElementAt_SkipFirstShouldBe { get; } = new("Use .Should().HaveElementAt()", GetHelpLink("Collections-26"));
public static DiagnosticMetadata CollectionShouldBeInAscendingOrder_OrderByShouldEqual { get; } = new("Use .Should().BeInAscendingOrder()", GetHelpLink("Collections-27"));
public static DiagnosticMetadata CollectionShouldBeInDescendingOrder_OrderByDescendingShouldEqual { get; } = new("Use .Should().BeInDescendingOrder()", GetHelpLink("Collections-28"));
public static DiagnosticMetadata CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect { get; } = new("Use .Should().BeEquivalentTo()", GetHelpLink("Collections-29"));
public static DiagnosticMetadata CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect { get; } = new("Use .Should().Equal()", GetHelpLink("Collections-29"));
public static DiagnosticMetadata CollectionShouldNotIntersectWith_IntersectShouldBeEmpty { get; } = new("Use .Should().NotIntersectWith()", GetHelpLink("Collections-30"));
public static DiagnosticMetadata CollectionShouldIntersectWith_IntersectShouldNotBeEmpty { get; } = new("Use .Should().IntersectWith()", GetHelpLink("Collections-31"));
public static DiagnosticMetadata CollectionShouldNotContainNulls_SelectShouldNotContainNulls { get; } = new("Use .Should().NotContainNulls()", GetHelpLink("Collections-32"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public const string DiagnosticId = "FAA0001";
public const string Message = "Clean up FluentAssertion usage";

protected static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, Message, Constants.Tips.Category, DiagnosticSeverity.Info, true);

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / Performance regression check

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)


public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);

Expand Down Expand Up @@ -179,7 +179,8 @@
case nameof(Enumerable.OrderByDescending) when IsEnumerableMethodWithPredicate(invocationBeforeShould, metadata) && invocationBeforeShould.Arguments[0].IsSameArgumentReference(assertion.Arguments[0]):
context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldBeInDescendingOrder_OrderByDescendingShouldEqual));
return;
case nameof(Enumerable.Select) when IsEnumerableMethodWithPredicate(invocationBeforeShould, metadata):
case nameof(Enumerable.Select) when IsEnumerableMethodWithPredicate(invocationBeforeShould, metadata)
&& assertion.Arguments[0].Value is IInvocationOperation { TargetMethod.Name: nameof(Enumerable.Select), Arguments.Length: 2 } expectedInvocation && expectedInvocation.Arguments[1].IsLambda():
context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect));
return;
}
Expand Down
Loading