-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Ignore dictionary types from HaveElementAt #45
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Linq; | ||
|
||
namespace FluentAssertions.Analyzers | ||
{ | ||
|
@@ -27,6 +28,16 @@ protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors | |
} | ||
} | ||
|
||
protected override bool ShouldAnalyzeVariableType(ITypeSymbol type) | ||
{ | ||
if (type.AllInterfaces.Any(@interface => @interface.Name == "IReadOnlyDictionary" || @interface.Name == "IDictionary")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the dictionary assertions are on the type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct, however, this is preventing the HaveIndexAt one from incorrectly firing on dictionaries. Since IDictionary doesn't inherit IReadOnlyDictionary I've done two checks (I use IReadOnlyDictionary in my interfaces which is where I found the bug). |
||
{ | ||
return false; | ||
} | ||
|
||
return base.ShouldAnalyzeVariableType(type); | ||
} | ||
|
||
public class ElementAtIndexShouldBeSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor | ||
{ | ||
public ElementAtIndexShouldBeSyntaxVisitor() : base(new MemberValidator("ElementAt"), MemberValidator.Should, new MemberValidator("Be")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to the collection analyzer without breaking tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do want some of the collection ones to still trigger on dictionaries (e.g.
Should().BeEmpty()
)