Class: Barcoop::Cop::Barcoo::AvoidTimeout

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Defined in:
lib/barcoop/cop/barcoo/avoid_timeout.rb

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object

def uncomment_to_test_this_cop()

Timeout.timeout(5) do
  _foo = 'Timeout.timeout sucks http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/'
end
timeout(5) do
  _bar = 'This is a deprecated call'
end

end



17
18
19
20
21
22
23
24
25
26
# File 'lib/barcoop/cop/barcoo/avoid_timeout.rb', line 17

def on_send(node)
  receiver, method_name = *node
  if method_name == :timeout
    if receiver.nil? || (receiver.const_type? && receiver.const_name == 'Timeout')
      # TODO: add a real link, like AtomLinter/linter-shellcheck
      msg = 'Timeout.timeout is not thread safe, see http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/'
      add_offense(node, :expression, msg)
    end
  end
end