class RuboCop::Cop::Lint::SwallowException

Public Instance Methods

has_raise?(node) click to toggle source
# File lib/rubocop/swallow_exception/cop/lint/swallow_exception.rb, line 32
def has_raise?(node)
  if node.type == :begin
    node.children.any? { |c| raise?(c) }
  else
    raise?(node)
  end
end
has_raven_capture_exception?(node) click to toggle source
# File lib/rubocop/swallow_exception/cop/lint/swallow_exception.rb, line 24
def has_raven_capture_exception?(node)
  if node.type == :begin
    node.children.any? { |c| raven_capture_exception?(c) }
  else
    raven_capture_exception?(node)
  end
end
on_resbody(node) click to toggle source
# File lib/rubocop/swallow_exception/cop/lint/swallow_exception.rb, line 7
        def on_resbody(node)
          # rescue の中身が空ならエラー
          unless node.children[2]
            add_offense(node, :expression, 'rescue body is empty!', :fatal)
            return
          end
          body = node.children[2]
          # トップレベルで条件なしに raise していれば OK
          return if has_raise?(body)
          # トップレベルで Raven.capture_exception 呼び出していれば OK
          return if has_raven_capture_exception?(body)
          # raise も Raven.capture_exception もなければエラー
          add_offense(node, :expression, (<<-MSG).strip, :fatal)
            you have to raise exception or capture exception by Raven in rescue body.
          MSG
        end
raise?(node) click to toggle source
# File lib/rubocop/swallow_exception/cop/lint/swallow_exception.rb, line 50
def raise?(node)
  node.type == :send &&
      node.children[0] == nil &&
      node.children[1] == :raise
end
raven?(node) click to toggle source
# File lib/rubocop/swallow_exception/cop/lint/swallow_exception.rb, line 46
def raven?(node)
  node && node.type == :const && node.children[1] == :Raven
end
raven_capture_exception?(node) click to toggle source
# File lib/rubocop/swallow_exception/cop/lint/swallow_exception.rb, line 40
def raven_capture_exception?(node)
  node.type == :send &&
      raven?(node.children[0]) &&
      node.children[1] == :capture_exception
end