lib/rubocop/cop/lint/inherit_exception.rb in rubocop-1.51.0 vs lib/rubocop/cop/lint/inherit_exception.rb in rubocop-1.52.0
- old
+ new
@@ -56,10 +56,11 @@
$(const {cbase nil?} _))
PATTERN
def on_class(node)
return unless node.parent_class && exception_class?(node.parent_class)
+ return if inherit_exception_class_with_omitted_namespace?(node)
message = message(node.parent_class)
add_offense(node.parent_class, message: message) do |corrector|
corrector.replace(node.parent_class, preferred_base_class)
@@ -83,9 +84,15 @@
format(MSG, prefer: preferred_base_class, current: node.const_name)
end
def exception_class?(class_node)
class_node.const_name == 'Exception'
+ end
+
+ def inherit_exception_class_with_omitted_namespace?(class_node)
+ return false if class_node.parent_class.namespace&.cbase_type?
+
+ class_node.left_siblings.any? { |sibling| exception_class?(sibling.identifier) }
end
def preferred_base_class
PREFERRED_BASE_CLASS[style]
end