Module: RuboCop::Cop::Style::MethodCallWithArgsParentheses::RequireParentheses

Defined in:
lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb

Overview

Style require_parentheses

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb', line 21

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(args_begin(node), '(')

    unless args_parenthesized?(node)
      corrector.insert_after(args_end(node), ')')
    end
  end
end

#message(_node = nil) ⇒ Object



31
32
33
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb', line 31

def message(_node = nil)
  'Use parentheses for method calls with arguments.'
end

#on_send(node) ⇒ Object Also known as: on_csend, on_super, on_yield



9
10
11
12
13
14
15
16
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb', line 9

def on_send(node)
  return if ignored_method?(node.method_name)
  return if matches_ignored_pattern?(node.method_name)
  return if eligible_for_parentheses_omission?(node)
  return unless node.arguments? && !node.parenthesized?

  add_offense(node)
end