Sha256: becc348448d30dd8d5e9a4b383f2fc1168701cd3e3a9253897f5ab3a85963844

Contents?: true

Size: 1.32 KB

Versions: 55

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      class MethodCallWithArgsParentheses
        # Style require_parentheses
        module RequireParentheses
          REQUIRE_MSG = 'Use parentheses for method calls with arguments.'
          private_constant :REQUIRE_MSG

          private

          def require_parentheses(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, message: REQUIRE_MSG) do |corrector|
              corrector.replace(args_begin(node), '(')

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

          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

55 entries across 55 versions & 6 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.27.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.26.1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.26.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.25.1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.25.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.24.1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.24.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.23.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.22.3 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.22.2 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.22.1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.22.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.21.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.20.0 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rubocop-1.19.1 lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb