Parent

Included Modules

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::RedundantBegin

This cop checks for redundant `begin` blocks.

Currently it checks for code like this:

@example

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

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/style/redundant_begin.rb, line 30
def autocorrect(node)
  @corrections << lambda do |corrector|
    child = node.children.first

    begin_indent = node.loc.column
    child_indent = child.loc.column

    indent_diff = child_indent - begin_indent

    corrector.replace(
      range_with_surrounding_space(node.loc.expression),
      range_with_surrounding_space(
        child.loc.expression
      ).source.gsub(/^\s{#{indent_diff}}/, '')
    )
  end
end
check(_node, _method_name, _args, body) click to toggle source
# File lib/rubocop/cop/style/redundant_begin.rb, line 24
def check(_node, _method_name, _args, body)
  return unless body && body.type == :kwbegin

  add_offense(body, :begin)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.