Adds support for attr_* method references#2848
Closed
tommycrumrine wants to merge 5 commits intoShopify:mainfrom
Closed
Adds support for attr_* method references#2848tommycrumrine wants to merge 5 commits intoShopify:mainfrom
tommycrumrine wants to merge 5 commits intoShopify:mainfrom
Conversation
tests. Prob can use some cleanup
Author
|
I have signed the CLA! |
vinistock
reviewed
Jan 7, 2025
Member
vinistock
left a comment
There was a problem hiding this comment.
Just a small change, but this looks great.
| def test_matches_attr_writer_with_call_node_argument | ||
| refs = find_method_references("foo=", <<~RUBY) | ||
| class Bar | ||
| attr_reader :foo, bar |
Member
There was a problem hiding this comment.
Should this be attr_writer or attr_accessor?
Author
There was a problem hiding this comment.
Thanks for the feedback @vinistock and apologies for the delay!! Heads up, I re-opened the PR here including fixes for both your comments.
|
|
||
| sig { params(node: Prism::CallNode).returns(T::Array[String]) } | ||
| def unescaped_argument_names(node) | ||
| node.arguments.arguments.select { |arg| arg.respond_to?(:unescaped) }.map(&:unescaped) |
Member
There was a problem hiding this comment.
In the middle of typing, we may find empty arguments, so we have to handle that. Also, we need to account for symbol and string nodes as arguments.
Suggested change
| node.arguments.arguments.select { |arg| arg.respond_to?(:unescaped) }.map(&:unescaped) | |
| arguments = node.arguments.arguments | |
| return [] unless arguments | |
| arguments.filter_map do |arg| | |
| case arg | |
| when Prism::StringNode | |
| arg.unescaped | |
| when Prism::SymbolNode | |
| arg.value | |
| end | |
| end |
Contributor
|
This pull request is being marked as stale because there was no activity in the last 2 months |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Shows references for methods defined with
attr_reader,attr_writer,attr_accessorCloses #2668
Implementation
attr_reader,attr_writer,attr_accessorare just methods, so on call node if we detect one of these methods, and one of the arguments match the target method name, add the reference.Automated Tests
ya
Manual Tests