Sha256: e67a578347c48ed0f320744c8d79b51425ab0029b46d5fe2e4d9f48bec6ba851
Contents?: true
Size: 1.25 KB
Versions: 15
Compression:
Stored size: 1.25 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 < Base include ConfigurableMax MSG = 'Avoid parameter lists longer than %<max>d parameters. ' \ '[%<count>d/%<max>d]' def on_args(node) count = args_count(node) return unless count > max_params return if argument_to_lambda_or_proc?(node) add_offense(node, message: format(MSG, max: max_params, count: args_count(node))) do self.max = count end end private def_node_matcher :argument_to_lambda_or_proc?, <<~PATTERN ^lambda_or_proc? PATTERN 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
15 entries across 15 versions & 3 rubygems