Sha256: dd1b3b47a5bf07af0e5974e1aa232829d307b7478f0707c99ecd717f770924f8

Contents?: true

Size: 1.29 KB

Versions: 6510

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Metrics
      # This cop checks for methods with too many parameters.
      # The maximum number of parameters is configurable.
      # Keyword arguments can optionally be excluded from the total count.
      class ParameterLists < Cop
        include ConfigurableMax

        MSG = 'Avoid parameter lists longer than %<max>d parameters. ' \
              '[%<count>d/%<max>d]'.freeze

        def on_args(node)
          count = args_count(node)
          return unless count > max_params

          return if argument_to_lambda_or_proc?(node)

          add_offense(node) do
            self.max = count
          end
        end

        private

        def_node_matcher :argument_to_lambda_or_proc?, <<-PATTERN
          ^lambda_or_proc?
        PATTERN

        def message(node)
          format(MSG, max: max_params, count: args_count(node))
        end

        def args_count(node)
          if count_keyword_args?
            node.children.size
          else
            node.children.count { |a| !%i[kwoptarg kwarg].include?(a.type) }
          end
        end

        def max_params
          cop_config['Max']
        end

        def count_keyword_args?
          cop_config['CountKeywordArgs']
        end
      end
    end
  end
end

Version data entries

6,510 entries across 6,504 versions & 25 rubygems

Version Path
cybrid_api_id_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_id_ruby-0.123.2 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_bank_ruby-0.123.2 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_organization_ruby-0.123.2 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_bank_ruby-0.122.72 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_organization_ruby-0.122.72 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_id_ruby-0.122.72 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_bank_ruby-0.122.71 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_id_ruby-0.122.71 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_organization_ruby-0.122.71 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_bank_ruby-0.122.70 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_organization_ruby-0.122.70 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_id_ruby-0.122.70 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_bank_ruby-0.122.69 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_id_ruby-0.122.69 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_organization_ruby-0.122.69 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_organization_ruby-0.122.68 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_bank_ruby-0.122.68 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_id_ruby-0.122.68 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb
cybrid_api_bank_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/metrics/parameter_lists.rb