Class: RuboCop::Cop::Legion::Framework::ThorReservedRun

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

Overview

Detects ‘def run` in Thor subclasses. Thor 1.5+ reserves the `run` method internally; defining it causes unexpected behavior.

Examples:

# bad
class MyCLI < Thor
  def run
    do_something
  end
end

# good
class MyCLI < Thor
  map 'run' => :execute

  def execute
    do_something
  end
end

Constant Summary collapse

MSG =
'Thor 1.5+ reserves `run`. Use `map "run" => :method_name` or rename the method.'
SEVERITY =
:warning

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ Object



30
31
32
33
34
35
# File 'lib/rubocop/cop/legion/framework/thor_reserved_run.rb', line 30

def on_def(node)
  return unless node.method_name == :run
  return unless inside_thor_class?(node)

  add_offense(node, severity: SEVERITY)
end