Class: Rubocop::Cop::Style::SignalException
- Defined in:
- lib/rubocop/cop/style/signal_exception.rb
Overview
This cop checks for uses of fail
and raise
.
Constant Summary collapse
- FAIL_MSG =
'Use `fail` instead of `raise` to signal exceptions.'
- RAISE_MSG =
'Use `raise` instead of `fail` to rethrow exceptions.'
Constants inherited from Cop
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, rails?, style?, #warning
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#autocorrect_action(node) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/rubocop/cop/style/signal_exception.rb', line 18 def autocorrect_action(node) @corrections << lambda do |corrector| name = command?(:raise, node) ? 'fail' : 'raise' corrector.replace(node.loc.selector, name) end end |
#on_rescue(node) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rubocop/cop/style/signal_exception.rb', line 11 def on_rescue(node) begin_node, rescue_node = *node check_for_raise(begin_node) check_for_fail(rescue_node) end |