Module: RuboCop::Cop::Kaizo::ArgumentCounting

Included in:
KeywordArguments, PositionalArguments, TotalArguments
Defined in:
lib/rubocop/cop/kaizo/argument_counting.rb

Overview

Shared traversal and counting for the argument-arity cops.

Walks method definitions written with def, def self., define_method, and define_singleton_method, and reports when the argument count produced by the including cop exceeds the configured Max. Including cops must define a private arity(arguments) method and a KIND constant. The initialize of a Struct.new/Data.define block is exempt.

Constant Summary collapse

POSITIONAL_TYPES =
%i[arg optarg].freeze
KEYWORD_TYPES =
%i[kwarg kwoptarg].freeze
DEFINE_METHODS =
%i[define_method define_singleton_method].freeze
STRUCT_OR_DATA =
{ "Struct" => :new, "Data" => :define }.freeze
MSG =
"Method has too many %<kind>s. [%<count>d/%<max>d]".freeze

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object Also known as: on_numblock, on_itblock



25
26
27
# File 'lib/rubocop/cop/kaizo/argument_counting.rb', line 25

def on_block(node)
  check_arity(node) if DEFINE_METHODS.include?(node.method_name)
end

#on_def(node) ⇒ Object Also known as: on_defs



18
19
20
21
22
# File 'lib/rubocop/cop/kaizo/argument_counting.rb', line 18

def on_def(node)
  return if allowed_initialize?(node)

  check_arity(node)
end