Parent

Included Modules

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::RescueModifier

This cop checks for uses of rescue in its modifier form.

Constants

MSG

Public Instance Methods

check(_node, _method_name, _args, body) click to toggle source
# File lib/rubocop/cop/style/rescue_modifier.rb, line 22
def check(_node, _method_name, _args, body)
  return unless body

  case body.type
  when :rescue
    ignore_node(body)
  when :ensure
    first_child = body.children.first
    if first_child && first_child.type == :rescue
      ignore_node(first_child)
    end
  end
end
on_kwbegin(node) click to toggle source
# File lib/rubocop/cop/style/rescue_modifier.rb, line 17
def on_kwbegin(node)
  body, *_ = *node
  check(nil, nil, nil, body)
end
on_rescue(node) click to toggle source
# File lib/rubocop/cop/style/rescue_modifier.rb, line 11
def on_rescue(node)
  return if ignored_node?(node)

  add_offense(node, :expression)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.