class RuboCop::Cop::Style::NestedParenthesizedCalls

This cop checks for unparenthesized method calls in the argument list of a parenthesized method call.

@example

@good
method1(method2(arg), method3(arg))

@bad
method1(method2 arg, method3, arg)

Constants

MSG
RSPEC_MATCHERS

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/style/nested_parenthesized_calls.rb, line 21
def on_send(node)
  return unless parenthesized_call?(node)

  node.each_child_node(:send) do |nested|
    next if nested.method_args.empty? ||
            parenthesized_call?(nested) ||
            operator?(nested.method_name) ||
            rspec_matcher?(node, nested) ||
            nested.asgn_method_call?
    add_offense(nested, nested.source_range, format(MSG, nested.source))
  end
end

Private Instance Methods

rspec_matcher?(parent, send) click to toggle source
# File lib/rubocop/cop/style/nested_parenthesized_calls.rb, line 36
def rspec_matcher?(parent, send)
  parent.method_args.one? && # .to, .not_to, etc
    RSPEC_MATCHERS.include?(send.method_name) &&
    send.method_args.one?
end