-
-
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
Conversation
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Since the dictionary assertions are on the type IDictionary
I think this should not look for the readonly one
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.
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).
@@ -414,6 +414,14 @@ public class CollectionTests | |||
[Implemented] | |||
public void CollectionShouldNotBeNullOrEmpty_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFixCodeBlock<CollectionShouldNotBeNullOrEmptyCodeFix, CollectionShouldNotBeNullOrEmptyAnalyzer>(oldAssertion, newAssertion); | |||
|
|||
[TestMethod] | |||
[Implemented] | |||
public void CollectionShouldHaveElementAt_ShouldIgnoreDictionaryTypes() |
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 this should be in the sanity tests and linked to its github issue
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.
Not a problem, didn't see that file 🙂
@@ -27,6 +28,16 @@ protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors | |||
} | |||
} | |||
|
|||
protected override bool ShouldAnalyzeVariableType(ITypeSymbol type) |
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()
)
@samcragg Thank you for your contribution 👍 |
This fixes #44 (thanks for the pointer of where to fix it!)