class RubbyCop::Cop::Style::RedundantBegin

This cop checks for redundant `begin` blocks.

Currently it checks for code like this:

@example

def redundant
  begin
    ala
    bala
  rescue StandardError => e
    something
  end
end

def preferred
  ala
  bala
rescue StandardError => e
  something
end

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubbycop/cop/style/redundant_begin.rb, line 38
def autocorrect(node)
  lambda do |corrector|
    corrector.remove(node.loc.begin)
    corrector.remove(node.loc.end)
  end
end
on_method_def(_node, _method_name, _args, body) click to toggle source
# File lib/rubbycop/cop/style/redundant_begin.rb, line 32
def on_method_def(_node, _method_name, _args, body)
  return unless body && body.kwbegin_type?

  add_offense(body, :begin)
end