Problem
Currently, in class_proxy.rb, ClassProxy does not provide any access to the start_line and end_line of the class definition. Although the node is stored but its location information (@node.location.start_line and @node.location.end_line) is not exposed.
This makes it difficult for visitors like method_call_visitor.rb to determine whether a private call appears inside the class body, especially with nested classes.
For example:
class Hello
private # visitor sees this, but it doesn't know the class Hello boundaries
def greet
puts "hello"
end
end
Suggested Solution
To solve this issue, we need to update both ClassProxy and the visitor logic.
- Update ClassProxy in class_proxy.rb by adding methods to expose the node's location data:
def start_line
@node.location.start_line
end
def end_line
@node.location.end_line
end
- Update Visitor Logic in method_call_visitor.rb:
class_proxy.method_calls ||= []
class_proxy.method_calls << node
return unless node.name == :private
node_start_line = node.location.start_line
# Provide safety checks to ensure ClassProxy supports boundaries
can_check_bounds = class_proxy.respond_to?(:start_line) && class_proxy.respond_to?(:end_line)
can_assign = class_proxy.respond_to?(:private_start_line=)
return unless can_check_bounds && can_assign
# Only track 'private' if it's actually inside the class body
if node_start_line > class_proxy.start_line && node_start_line < class_proxy.end_line
class_proxy.private_start_line = node_start_line
end
This will ensure that the method visibility is tracked accurately and doesn't "leak" between nested classes or separate class definitions in the same file. @maedi brother, I'm planning to work on this issue. Before I start, I would love to get some feedback from you.
Problem
Currently, in class_proxy.rb, ClassProxy does not provide any access to the start_line and end_line of the class definition. Although the node is stored but its location information (@node.location.start_line and @node.location.end_line) is not exposed.
This makes it difficult for visitors like method_call_visitor.rb to determine whether a
privatecall appears inside the class body, especially with nested classes.For example:
Suggested Solution
To solve this issue, we need to update both ClassProxy and the visitor logic.
This will ensure that the method visibility is tracked accurately and doesn't "leak" between nested classes or separate class definitions in the same file. @maedi brother, I'm planning to work on this issue. Before I start, I would love to get some feedback from you.