Class: RuboCop::Cop::Legion::Llm::NoLoopDo

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

Overview

Flags ‘loop do` in legion-llm production code. Unbounded loops have caused runaway threads and hard-to-debug hangs. Use `N.times`, `each`, or a `while` with an explicit counter instead.

No auto-correct is provided — the fix requires choosing the correct bound.

Examples:

# bad
loop do
  attempt = dispatch_request
  break if attempt.success?
end

# good
MAX_ATTEMPTS.times do
  attempt = dispatch_request
  break if attempt.success?
end

Constant Summary collapse

MSG =
'`loop do` is prohibited — use bounded iteration (`N.times`, `each`, ' \
'or `while` with an explicit decrement) instead.'

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object Also known as: on_numblock



29
30
31
32
33
34
# File 'lib/rubocop/cop/legion/llm/no_loop_do.rb', line 29

def on_block(node)
  return unless node.send_node.method_name == :loop
  return unless node.send_node.receiver.nil?

  add_offense(node.send_node)
end