Skip to content

Commit

Permalink
Introduce lhs and rhs aliases to assignment nodes for consistency.
Browse files Browse the repository at this point in the history
The methods are already available for `masgn`, so this will allow all assignment node types to have the same two methods so that they can be dealt with in unison.
  • Loading branch information
dvandersluis authored and marcandre committed Nov 4, 2024
1 parent c5c3b04 commit 4816b55
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rubocop/ast/node/asgn_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class AsgnNode < Node
def name
node_parts[0]
end
alias lhs name

# The expression being assigned to the variable.
#
# @return [Node] the expression being assigned.
def expression
node_parts[1]
end
alias rhs expression
end
end
end
2 changes: 2 additions & 0 deletions lib/rubocop/ast/node/casgn_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class CasgnNode < Node
include ConstantNode

alias name short_name
alias lhs short_name

# The expression being assigned to the variable.
#
# @return [Node] the expression being assigned.
def expression
node_parts[2]
end
alias rhs expression
end
end
end
2 changes: 2 additions & 0 deletions lib/rubocop/ast/node/op_asgn_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class OpAsgnNode < Node
def assignment_node
node_parts[0]
end
alias lhs assignment_node

# The name of the variable being assigned as a symbol.
#
Expand All @@ -31,6 +32,7 @@ def operator
def expression
node_parts.last
end
alias rhs expression
end
end
end

0 comments on commit 4816b55

Please sign in to comment.