Class: Reek::SmellDetectors::LongYieldList

Inherits:
BaseDetector show all
Defined in:
lib/reek/smell_detectors/long_yield_list.rb

Overview

A variant on LongParameterList that checks the number of items passed to a block by a yield call.

See Long-Yield-List for details.

Constant Summary collapse

MAX_ALLOWED_PARAMS_KEY =

The name of the config field that sets the maximum number of parameters permitted in any method or block.

'max_params'
DEFAULT_MAX_ALLOWED_PARAMS =
3

Constants inherited from BaseDetector

BaseDetector::DEFAULT_EXCLUDE_SET, BaseDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from BaseDetector

#config, #context

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDetector

#config_for, configuration_keys, contexts, descendants, #enabled?, #exception?, #expression, inherited, #initialize, #run, #smell_type, smell_type, #smell_warning, #source_line, to_detector, todo_configuration_for, #value

Constructor Details

This class inherits a constructor from Reek::SmellDetectors::BaseDetector

Class Method Details

.default_configObject



18
19
20
# File 'lib/reek/smell_detectors/long_yield_list.rb', line 18

def self.default_config
  super.merge MAX_ALLOWED_PARAMS_KEY => DEFAULT_MAX_ALLOWED_PARAMS
end

Instance Method Details

#max_allowed_paramsObject (private)



42
43
44
# File 'lib/reek/smell_detectors/long_yield_list.rb', line 42

def max_allowed_params
  value(MAX_ALLOWED_PARAMS_KEY, context)
end

#sniffArray<SmellWarning>

Checks the number of parameters in the given scope.

Returns:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/reek/smell_detectors/long_yield_list.rb', line 28

def sniff
  context.local_nodes(:yield).select do |yield_node|
    yield_node.args.length > max_allowed_params
  end.map do |yield_node|
    count = yield_node.args.length
    smell_warning(
      lines: [yield_node.line],
      message: "yields #{count} parameters",
      parameters: { count: count })
  end
end