Class: RuboCop::Cop::Kaizo::TotalArguments

Inherits:
Base
  • Object
show all
Includes:
ArgumentCounting
Defined in:
lib/rubocop/cop/kaizo/total_arguments.rb

Overview

Checks that a method does not declare too many arguments in total (positional plus keyword).

The goal is to apply pressure toward good domain modeling: a long argument list is often a sign of primitive obsession, and bundling the related values into an object usually expresses the intent better.

*rest, **keyword-rest, and &block arguments are not counted. The initialize of a Struct.new/Data.define block is exempt, since those parameters mirror the value object's attributes.

Configuration

[+Max+] Most arguments -- positional plus keyword -- a method may declare. Default: 2. [+AllowedMethods+] Method names exempt from the limit. Default: none. [+AllowedPatterns+] Regexps matched against the method name; a match is exempt. Default: none. [+Exclude+] Paths the cop skips. Default: **/spec// and */test//*, matching KeywordArguments -- a total bound would re-police the keyword freedom tests get. PositionalArguments alone still bounds positional arguments there. Set it to [] to police tests too.

Kaizo/TotalArguments:
Max: 3
AllowedMethods:
  - initialize

Examples:

Max: 3

# bad
def calculate_volume(width, length, height, shape_type)
end

# good
def calculate_volume(shape)
end

Constant Summary collapse

KIND =
"arguments".freeze

Constants included from ArgumentCounting

ArgumentCounting::DEFINE_METHODS, ArgumentCounting::KEYWORD_TYPES, ArgumentCounting::MSG, ArgumentCounting::OPERATOR_METHOD_NAMES, ArgumentCounting::POSITIONAL_TYPES, ArgumentCounting::STRUCT_OR_DATA

Method Summary

Methods included from ArgumentCounting

#on_block, #on_def