Skip to content

Commit

Permalink
Refactor WrappedArgumentsNode => ParameterizedNode::WrappedArguments
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Aug 1, 2020
1 parent 31fdd27 commit 11ef5c0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
1 change: 0 additions & 1 deletion lib/rubocop/ast.rb
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions lib/rubocop/ast/node/break_node.rb
Expand Up @@ -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
16 changes: 16 additions & 0 deletions lib/rubocop/ast/node/mixin/parameterized_node.rb
Expand Up @@ -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]`
Expand Down
19 changes: 0 additions & 19 deletions lib/rubocop/ast/node/mixin/wrapped_arguments_node.rb

This file was deleted.

3 changes: 1 addition & 2 deletions lib/rubocop/ast/node/next_node.rb
Expand Up @@ -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
3 changes: 1 addition & 2 deletions lib/rubocop/ast/node/return_node.rb
Expand Up @@ -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

0 comments on commit 11ef5c0

Please sign in to comment.