-
Notifications
You must be signed in to change notification settings - Fork 172
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
Adds support for attr_* method references #2848
base: main
Are you sure you want to change the base?
Adds support for attr_* method references #2848
Conversation
tests. Prob can use some cleanup
I have signed the CLA! |
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.
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 |
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.
Should this be attr_writer
or attr_accessor
?
|
||
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) |
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.
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.
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 |
Motivation
Shows references for methods defined with
attr_reader
,attr_writer
,attr_accessor
Closes #2668
Implementation
attr_reader
,attr_writer
,attr_accessor
are 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