Class: RuboCop::Cop::Metz::DemeterTrainWreck

Inherits:
Base
  • Object
show all
Extended by:
Metz::CopMetadata
Includes:
OnSendCsendBridge
Defined in:
lib/rubocop/cop/metz/demeter_train_wreck.rb,
lib/rubocop/cop/metz/demeter_train_wreck/type_inference.rb

Overview

Flags Law-of-Demeter-violating object-graph traversal chains while staying quiet on long value-object chains. Walks the send chain downward via node.receiver, skipping pass-through methods, allowed constant receivers, and operator/setter sends. Recognises core value-object methods through TypeInference::METHOD_RETURN_TYPES and uses a reverse-lookup heuristic on the method name to escape an unknown innermost receiver.

Direct Known Subclasses

ViewsDeepNavigation

Defined Under Namespace

Modules: TypeInference

Constant Summary collapse

MSG =
"Object-graph traversal of %<count>d exceeds Max (%<max>d). " \
"Consider delegating or wrapping intermediate calls."

Constants included from Metz::CopMetadata

Metz::CopMetadata::DEFAULT_FIX_SAFETY, Metz::CopMetadata::DEFAULT_SUGGESTED_NEXT_MOVES, Metz::CopMetadata::DEFAULT_WHY_IT_MATTERS

Instance Method Summary collapse

Methods included from Metz::CopMetadata

fix_safety, included, metz_metadata, suggested_next_moves, why_it_matters

Methods included from OnSendCsendBridge

included

Instance Method Details

#on_send(node) ⇒ Object



32
33
34
35
36
37
# File 'lib/rubocop/cop/metz/demeter_train_wreck.rb', line 32

def on_send(node)
  return if part_of_outer_chain?(node)
  return if outermost_skippable?(node)

  analyze(node)
end