class RubbyCop::Cop::Lint::UnreachableCode
This cop checks for unreachable code. The check are based on the presence of flow of control statement in non-final position in begin(implicit) blocks.
@example
# bad def some_method return do_something end
@example
# good def some_method do_something end
Constants
- FLOW_COMMANDS
- MSG
- NODE_TYPES
Public Instance Methods
on_begin(node)
click to toggle source
# File lib/rubbycop/cop/lint/unreachable_code.rb, line 32 def on_begin(node) expressions = *node expressions.each_cons(2) do |e1, e2| next unless NODE_TYPES.include?(e1.type) || flow_command?(e1) add_offense(e2, :expression) end end
Private Instance Methods
flow_command?(node)
click to toggle source
# File lib/rubbycop/cop/lint/unreachable_code.rb, line 44 def flow_command?(node) return false unless node.send_type? FLOW_COMMANDS.any? { |c| node.command?(c) } end