Class: Rubocop::Cop::Style::RedundantBegin

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/style/redundant_begin.rb

Overview

This cop checks for redundant begin blocks.

Currently it checks for code like this:

Examples:


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

Constant Summary collapse

MSG =
'Redundant `begin` block detected.'

Constants inherited from Cop

Cop::OPERATOR_METHODS

Instance Attribute Summary

Attributes inherited from Cop

#config, #corrections, #offences, #processed_source

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, all, #autocorrect?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, non_rails, rails?, style?, #support_autocorrect?, #warning

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#on_def(node) ⇒ Object



23
24
25
26
27
# File 'lib/rubocop/cop/style/redundant_begin.rb', line 23

def on_def(node)
  _method_name, _args, body = *node

  check(body)
end

#on_defs(node) ⇒ Object



29
30
31
32
33
# File 'lib/rubocop/cop/style/redundant_begin.rb', line 29

def on_defs(node)
  _scope, _method_name, _args, body = *node

  check(body)
end