Class: RuboCop::Cop::Legion::Extension::RunnerReturnHash

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/legion/extension/runner_return_hash.rb

Overview

Detects explicit ‘return` of non-Hash values inside runner modules. LEX runner methods must return a Hash so the framework can process the result and chain tasks correctly.

Examples:

# bad
module Runners
  module Foo
    def run
      return "error"
    end
  end
end

# good
module Runners
  module Foo
    def run
      return { success: false, message: "error" }
    end
  end
end

Constant Summary collapse

MSG =
'Runner methods must return a Hash. Found explicit return of non-Hash value.'

Instance Method Summary collapse

Instance Method Details

#on_return(node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/legion/extension/runner_return_hash.rb', line 32

def on_return(node)
  return unless inside_runners_namespace?(node)
  return if node.children.empty?

  value = node.children.first
  return if value.nil?
  return if value.hash_type?

  add_offense(node)
end