Class: RuboCop::Cop::OpenProject::NoNotImplementedError

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/open_project/no_not_implemented_error.rb

Overview

Warns against using a ‘NotImplementedError` exception when a method should be implemented by a subclass or including module. Ruby’s ‘NotImplementedError` is reserved for platform-specific missing features (e.g., methods depending on `fsync` or `fork`), not for abstract method patterns.

Examples:

# bad
raise NotImplementedError

# bad
raise NotImplementedError, "Subclasses must implement #foo"

# bad
raise NotImplementedError.new("Subclasses must implement #foo")

# bad
fail NotImplementedError

# good
raise NotYetImplementedError

# good
raise SubclassResponsibilityError, "#{self.class} must implement #foo"

Constant Summary collapse

MSG =
"Do not raise `NotImplementedError` to signal an unimplemented abstract method. " \
"Ruby's `NotImplementedError` is reserved for platform-specific missing features. " \
"Raise a descriptive custom error class instead."
RESTRICT_ON_SEND =
%i[raise fail].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



45
46
47
48
49
# File 'lib/rubocop/cop/open_project/no_not_implemented_error.rb', line 45

def on_send(node)
  return unless raises_not_implemented_error?(node)

  add_offense(node)
end