Class: RuboCop::Cop::SortedMethodsByCall::Waterfall
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::SortedMethodsByCall::Waterfall
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/sorted_methods_by_call/waterfall.rb
Overview
Enforces “waterfall” ordering: define a method after any method that calls it within the same scope. Produces a top-down reading flow where orchestration appears before implementation details.
-
Scopes: class/module/sclass (top-level can be analyzed via on_begin)
-
Offense: when a callee is defined above its caller
-
Autocorrect: UNSAFE; reorders methods within a contiguous visibility section (does not cross other statements or nested scopes). Preserves leading doc comments on each method. Skips cycles and non-contiguous groups.
Configuration
-
AllowedRecursion [Boolean] (default: true)
If true, the cop ignores violations that are part of a mutual recursion cycle (callee → … → caller). If false, such cycles are reported. -
SafeAutoCorrect [Boolean] (default: false)
Autocorrection is unsafe and only runs under -A, never under -a.
Constant Summary collapse
- MSG =
Template message for offenses where a callee appears before its caller.
'Define %<callee>s after its caller %<caller>s (waterfall order).'
Instance Method Summary collapse
-
#on_begin(node) ⇒ void
Entry point for root :begin nodes (top-level).
-
#on_class(node) ⇒ void
Entry point for class scopes.
-
#on_module(node) ⇒ void
Entry point for module scopes.
-
#on_sclass(node) ⇒ void
Entry point for singleton class scopes (class << self).
Instance Method Details
#on_begin(node) ⇒ void
This method returns an undefined value.
Entry point for root :begin nodes (top-level).
Whether top-level is analyzed depends on how the code is structured; by default we only analyze class/module/sclass scopes, but top-level is supported through this hook.
84 85 86 |
# File 'lib/rubocop/cop/sorted_methods_by_call/waterfall.rb', line 84 def on_begin(node) analyze_scope(node) end |
#on_class(node) ⇒ void
This method returns an undefined value.
Entry point for class scopes.
92 93 94 |
# File 'lib/rubocop/cop/sorted_methods_by_call/waterfall.rb', line 92 def on_class(node) analyze_scope(node) end |
#on_module(node) ⇒ void
This method returns an undefined value.
Entry point for module scopes.
100 101 102 |
# File 'lib/rubocop/cop/sorted_methods_by_call/waterfall.rb', line 100 def on_module(node) analyze_scope(node) end |
#on_sclass(node) ⇒ void
This method returns an undefined value.
Entry point for singleton class scopes (class << self).
108 109 110 |
# File 'lib/rubocop/cop/sorted_methods_by_call/waterfall.rb', line 108 def on_sclass(node) analyze_scope(node) end |