diff --git a/lib/rubocop/ast.rb b/lib/rubocop/ast.rb index dd9f6bcff..db59188bd 100644 --- a/lib/rubocop/ast.rb +++ b/lib/rubocop/ast.rb @@ -18,7 +18,6 @@ require_relative 'ast/node/mixin/parameterized_node' require_relative 'ast/node/mixin/predicate_operator_node' require_relative 'ast/node/mixin/basic_literal_node' -require_relative 'ast/node/mixin/wrapped_arguments_node' require_relative 'ast/node/alias_node' require_relative 'ast/node/and_node' require_relative 'ast/node/args_node' diff --git a/lib/rubocop/ast/node/break_node.rb b/lib/rubocop/ast/node/break_node.rb index 5e1e14396..447b4cb63 100644 --- a/lib/rubocop/ast/node/break_node.rb +++ b/lib/rubocop/ast/node/break_node.rb @@ -6,8 +6,7 @@ module AST # plain node when the builder constructs the AST, making its methods # available to all `break` nodes within RuboCop. class BreakNode < Node - include ParameterizedNode - include WrappedArgumentsNode + include ParameterizedNode::WrappedArguments end end end diff --git a/lib/rubocop/ast/node/mixin/parameterized_node.rb b/lib/rubocop/ast/node/mixin/parameterized_node.rb index 4e6e04917..0a08cfa34 100644 --- a/lib/rubocop/ast/node/mixin/parameterized_node.rb +++ b/lib/rubocop/ast/node/mixin/parameterized_node.rb @@ -60,6 +60,22 @@ def block_argument? (last_argument.block_pass_type? || last_argument.blockarg_type?) end + # A specialized `ParameterizedNode` for node that have a single child + # containing either `nil`, an argument, or a `begin` node with all the + # arguments + module WrappedArguments + include ParameterizedNode + # @return [Array] The arguments of the node. + def arguments + first = children.first + if first&.begin_type? + first.children + else + children + end + end + end + # A specialized `ParameterizedNode`. # Requires implementing `first_argument_index` # Implements `arguments` as `children[first_argument_index..-1]` diff --git a/lib/rubocop/ast/node/mixin/wrapped_arguments_node.rb b/lib/rubocop/ast/node/mixin/wrapped_arguments_node.rb deleted file mode 100644 index 56e3b10b1..000000000 --- a/lib/rubocop/ast/node/mixin/wrapped_arguments_node.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module AST - # Common functionality for nodes that may have their arguments - # wrapped in a `begin` node - module WrappedArgumentsNode - # @return [Array] The arguments of the node. - def arguments - first = children.first - if first&.begin_type? - first.children - else - children - end - end - end - end -end diff --git a/lib/rubocop/ast/node/next_node.rb b/lib/rubocop/ast/node/next_node.rb index 1f7b9dcc1..871561311 100644 --- a/lib/rubocop/ast/node/next_node.rb +++ b/lib/rubocop/ast/node/next_node.rb @@ -6,8 +6,7 @@ module AST # plain node when the builder constructs the AST, making its methods # available to all `next` nodes within RuboCop. class NextNode < Node - include ParameterizedNode - include WrappedArgumentsNode + include ParameterizedNode::WrappedArguments end end end diff --git a/lib/rubocop/ast/node/return_node.rb b/lib/rubocop/ast/node/return_node.rb index a8d617f88..a3495e646 100644 --- a/lib/rubocop/ast/node/return_node.rb +++ b/lib/rubocop/ast/node/return_node.rb @@ -6,8 +6,7 @@ module AST # plain node when the builder constructs the AST, making its methods # available to all `return` nodes within RuboCop. class ReturnNode < Node - include ParameterizedNode - include WrappedArgumentsNode + include ParameterizedNode::WrappedArguments end end end