-
-
Notifications
You must be signed in to change notification settings - Fork 63
Add MA0179: Detect inefficient attribute existence checks #939
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
Conversation
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
…n negation logic Co-authored-by: meziantou <[email protected]>
…cription Co-authored-by: meziantou <[email protected]>
|
@copilot Can you also detect |
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
Done! Added support for detecting
Commit: a491f10 |
|
@copilot Can you add a test for |
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
Done!
|
| { | ||
| var operation = (IInvocationOperation)context.Operation; | ||
|
|
||
| if (operation.TargetMethod.Name != "Any") |
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.
@copilot Can you be more specific and use a IMethodSymbol to actually compare it or check if the method is defined in System.Linq.Enumerable
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.
Done! Changed to use specific IMethodSymbol comparison via DocumentationCommentId.GetFirstSymbolForDeclarationId for both Any and Count methods. This ensures we only detect the exact System.Linq.Enumerable.Any<T>(IEnumerable<T>) and System.Linq.Enumerable.Count<T>(IEnumerable<T>) methods, making the detection more precise and robust.
| { | ||
| void Test(MemberInfo member) | ||
| { | ||
| _ = [||]member.GetCustomAttribute<ObsoleteAttribute>() != null; |
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.
@copilot Use the correct scope here and in every tests
| _ = [||]member.GetCustomAttribute<ObsoleteAttribute>() != null; | |
| _ = [|member.GetCustomAttribute<ObsoleteAttribute>() != null|]; |
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.
Fixed! Changed all test diagnostic markers from [||]expression to [|expression|] to properly indicate the diagnostic span scope.
Commit: 6ea0409
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
Summary
Successfully implemented MA0179: Use Attribute.IsDefined instead of GetCustomAttribute(s)
Completed Tasks
Latest Changes
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.