diff --git a/changelog/change_mark_lint_inherit_exception_as_unsafe.md b/changelog/change_mark_lint_inherit_exception_as_unsafe.md new file mode 100644 index 00000000000..1d62444dcc7 --- /dev/null +++ b/changelog/change_mark_lint_inherit_exception_as_unsafe.md @@ -0,0 +1 @@ +* [#10408](https://github.com/rubocop/rubocop/pull/10408): Mark `Lint/InheritException` as unsafe auto-correction. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index 71c48830b0b..ade37e44762 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1816,7 +1816,9 @@ Lint/IneffectiveAccessModifier: Lint/InheritException: Description: 'Avoid inheriting from the `Exception` class.' Enabled: true + SafeAutoCorrect: false VersionAdded: '0.41' + VersionChanged: '<>' # The default base class in favour of `Exception`. EnforcedStyle: runtime_error SupportedStyles: diff --git a/lib/rubocop/cop/lint/inherit_exception.rb b/lib/rubocop/cop/lint/inherit_exception.rb index e3f61658008..06e45f01f6b 100644 --- a/lib/rubocop/cop/lint/inherit_exception.rb +++ b/lib/rubocop/cop/lint/inherit_exception.rb @@ -8,6 +8,11 @@ module Lint # `StandardError`. It is configurable to suggest using either # `RuntimeError` (default) or `StandardError` instead. # + # @safety + # This cop's autocorrection is unsafe because `rescue` that omit + # exception class handle `StandardError` and its subclasses, + # but not `Exception` and its subclasses. + # # @example EnforcedStyle: runtime_error (default) # # bad #