class RubbyCop::Cop::Style::MethodCallWithArgsParentheses

This cop checks presence of parentheses in method calls containing parameters. By default, macro methods are ignored. Additional methods can be added to the `IgnoredMethods` list.

@example

# bad
array.delete e

# good
array.delete(e)

# good
# Operators don't need parens
foo == bar

# good
# Setter methods don't need parens
foo.bar = baz

# okay with `puts` listed in `IgnoredMethods`
puts 'test'

# IgnoreMacros: true (default)

# good
class Foo
  bar :baz
end

# IgnoreMacros: false

# bad
class Foo
  bar :baz
end

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 67
def autocorrect(node)
  lambda do |corrector|
    corrector.replace(args_begin(node), '(')
    corrector.insert_after(args_end(node), ')')
  end
end
on_send(node) click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 45
def on_send(node)
  return if ignored_method?(node)
  return unless node.arguments? && !node.parenthesized?

  add_offense(node, :selector)
end
on_super(node) click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 52
def on_super(node)
  # super nodetype implies call with arguments.
  return if parentheses?(node)

  add_offense(node, :keyword)
end
on_yield(node) click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 59
def on_yield(node)
  args = node.children
  return if args.empty?
  return if parentheses?(node)

  add_offense(node, :keyword)
end

Private Instance Methods

args_begin(node) click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 94
def args_begin(node)
  loc = node.loc
  selector =
    node.super_type? || node.yield_type? ? loc.keyword : loc.selector
  selector.end.resize(1)
end
args_end(node) click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 101
def args_end(node)
  node.loc.expression.end
end
ignore_macros?() click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 86
def ignore_macros?
  cop_config['IgnoreMacros']
end
ignored_list() click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 82
def ignored_list
  cop_config['IgnoredMethods'].map(&:to_sym)
end
ignored_method?(node) click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 76
def ignored_method?(node)
  node.operator_method? || node.setter_method? ||
    ignore_macros? && node.macro? ||
    ignored_list.include?(node.method_name)
end
parentheses?(node) click to toggle source
# File lib/rubbycop/cop/style/method_call_with_args_parentheses.rb, line 90
def parentheses?(node)
  node.loc.begin
end