From 4816b55e51b07c6cd180c31aa6ec1becd61f874b Mon Sep 17 00:00:00 2001 From: Daniel Vandersluis Date: Mon, 4 Nov 2024 10:20:39 -0500 Subject: [PATCH] Introduce `lhs` and `rhs` aliases to assignment nodes for consistency. 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. --- lib/rubocop/ast/node/asgn_node.rb | 2 ++ lib/rubocop/ast/node/casgn_node.rb | 2 ++ lib/rubocop/ast/node/op_asgn_node.rb | 2 ++ 3 files changed, 6 insertions(+) diff --git a/lib/rubocop/ast/node/asgn_node.rb b/lib/rubocop/ast/node/asgn_node.rb index 9931b9b73..90d0cf119 100644 --- a/lib/rubocop/ast/node/asgn_node.rb +++ b/lib/rubocop/ast/node/asgn_node.rb @@ -12,6 +12,7 @@ class AsgnNode < Node def name node_parts[0] end + alias lhs name # The expression being assigned to the variable. # @@ -19,6 +20,7 @@ def name def expression node_parts[1] end + alias rhs expression end end end diff --git a/lib/rubocop/ast/node/casgn_node.rb b/lib/rubocop/ast/node/casgn_node.rb index 617c8c70c..31382d8f5 100644 --- a/lib/rubocop/ast/node/casgn_node.rb +++ b/lib/rubocop/ast/node/casgn_node.rb @@ -9,6 +9,7 @@ class CasgnNode < Node include ConstantNode alias name short_name + alias lhs short_name # The expression being assigned to the variable. # @@ -16,6 +17,7 @@ class CasgnNode < Node def expression node_parts[2] end + alias rhs expression end end end diff --git a/lib/rubocop/ast/node/op_asgn_node.rb b/lib/rubocop/ast/node/op_asgn_node.rb index a81a1eb33..f425e63b1 100644 --- a/lib/rubocop/ast/node/op_asgn_node.rb +++ b/lib/rubocop/ast/node/op_asgn_node.rb @@ -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. # @@ -31,6 +32,7 @@ def operator def expression node_parts.last end + alias rhs expression end end end