Module: RuboCop::Cop::Style::MethodCallWithArgsParentheses::OmitParentheses

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

Overview

Style omit_parentheses

Constant Summary collapse

TRAILING_WHITESPACE_REGEX =
/\s+\Z/.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb', line 24

def autocorrect(node)
  lambda do |corrector|
    if parentheses_at_the_end_of_multiline_call?(node)
      corrector.replace(args_begin(node), ' \\')
    else
      corrector.replace(args_begin(node), ' ')
    end
    corrector.remove(node.loc.end)
  end
end

#message(_node = nil) ⇒ Object



35
36
37
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb', line 35

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

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



11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb', line 11

def on_send(node)
  return unless node.parenthesized?
  return if node.implicit_call?
  return if super_call_without_arguments?(node)
  return if allowed_camel_case_method_call?(node)
  return if legitimate_call_with_parentheses?(node)

  add_offense(node, location: node.loc.begin.join(node.loc.end))
end