Class: Reek::SmellDetectors::ManualDispatch

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

Overview

A Manual Dispatch occurs when a method is only called after a manual check that the method receiver is of the correct type.

The ManualDispatch checker reports any invocation of respond_to?

See Manual-Dispatch for details.

Constant Summary collapse

MESSAGE =
'manually dispatches method call'

Constants inherited from BaseDetector

BaseDetector::DEFAULT_EXCLUDE_SET, BaseDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from BaseDetector

#config, #context

Instance Method Summary collapse

Methods inherited from BaseDetector

#config_for, configuration_keys, contexts, default_config, 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

Instance Method Details

#sniffArray<SmellWarning>

Checks for respond_to? usage within the given method

Returns:



22
23
24
25
26
27
28
# File 'lib/reek/smell_detectors/manual_dispatch.rb', line 22

def sniff
  smelly_nodes = context.local_nodes(:send).select { |node| node.name == :respond_to? }
  return [] if smelly_nodes.empty?

  lines = smelly_nodes.map(&:line)
  [smell_warning(lines: lines, message: MESSAGE)]
end