Sha256: 5c62db750c7645d768acda2b9edea7a7494185e9c85c326cdfc3e70011b2f8bf

Contents?: true

Size: 1.44 KB

Versions: 13

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      class MethodCallWithArgsParentheses
        # Style require_parentheses
        module RequireParentheses
          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
          alias on_csend on_send
          alias on_super on_send
          alias on_yield on_send

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

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

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

          private

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

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

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

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
rubocop-0.89.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-0.88.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-0.87.1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-0.87.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-0.86.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-0.85.1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-0.85.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-0.84.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb