123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb

Overview

Style require_parentheses

Constant Summary

Instance Method Summary

Instance Method Details

#allowed_method_name?(name) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb', line 27

def allowed_method_name?(name)
  allowed_method?(name) || matches_allowed_pattern?(name)
end

#eligible_for_parentheses_omission?(node) ⇒ Boolean (private)

[ GitHub ]

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

def eligible_for_parentheses_omission?(node)
  node.operator_method? || node.setter_method? || ignored_macro?(node)
end

#ignored_macro?(node) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb', line 39

def ignored_macro?(node)
  cop_config['IgnoreMacros'] &&
    node.macro? &&
    !included_macros_list.include?(node.method_name)
end

#included_macros_list (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb', line 35

def included_macros_list
  cop_config.fetch('IncludedMacros', []).map(&:to_sym)
end

#require_parentheses(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb', line 14

def require_parentheses(node)
  return if allowed_method_name?(node.method_name)
  return if matches_allowed_pattern?(node.method_name)
  return if eligible_for_parentheses_omission?(node)
  return unless node.arguments? && !node.parenthesized?

  add_offense(node, message: REQUIRE_MSG) do |corrector|
    corrector.replace(args_begin(node), '(')

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