Sha256: 058be0b1db769851ba7060454580c32a924dfe7f9c4b99ffaf95103ec8059cbf

Contents?: true

Size: 1000 Bytes

Versions: 4

Compression:

Stored size: 1000 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop checks for methods with too many parameters.
      # The maximum number of parameters in configurable.
      # On Ruby 2.0+ keyword arguments can optionally
      # be excluded from the total count.
      class ParameterLists < Cop
        MSG = 'Avoid parameter lists longer than %d parameters.'

        def on_args(node)
          if args_count(node) > max_params
            add_offence(:convention, node.loc.expression,
                        sprintf(MSG, max_params))
          end
        end

        private

        def args_count(node)
          if count_keyword_args?
            node.children.size
          else
            node.children.reject { |a| a.type == :kwoptarg }.size
          end
        end

        def max_params
          ParameterLists.config['Max']
        end

        def count_keyword_args?
          ParameterLists.config['CountKeywordArgs']
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.12.0 lib/rubocop/cop/style/parameter_lists.rb
rubocop-0.11.1 lib/rubocop/cop/style/parameter_lists.rb
rubocop-0.11.0 lib/rubocop/cop/style/parameter_lists.rb
rubocop-0.10.0 lib/rubocop/cop/style/parameter_lists.rb