Class: RuboCop::Cop::Ezcater::RequireCustomError

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/ezcater/require_custom_error.rb

Overview

Checks for ‘raise` on `StandardError` and `ArgumentError`. We want to be explicit about the error we’re raising and use a custom error

Examples:

# bad
raise StandardError, "You can't do that"

# good
raise OrderActionNotAllowed

Constant Summary collapse

MSG =
"Use a custom error class that inherits from StandardError when raising an exception"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/rubocop/cop/ezcater/require_custom_error.rb', line 25

def on_send(node)
  raising_standard_or_argument_error(node) do
    add_offense(node, message: format(MSG))
  end

  initializing_standard_or_argument_error(node) do
    add_offense(node, message: format(MSG))
  end
end