Skip to content

Commit

Permalink
Mark Lint/InheritException as unsafe auto-correction
Browse files Browse the repository at this point in the history
This PR marks `Lint/InheritException` as unsafe auto-correction.

This cop's autocorrection is unsafe because `rescue` that omit
exception class handle `StandardError` and its subclasses,
but not `Exception` and its subclasses.

```ruby
begin
rescue # Handles only `StandardError` and its subclasses because exception class is omitted.
end
```

It's still unsafe after #10406 is resolved.
  • Loading branch information
koic committed Feb 9, 2022
1 parent af609e5 commit bc9d310
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions 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][])
2 changes: 2 additions & 0 deletions config/default.yml
Expand Up @@ -1816,7 +1816,9 @@ Lint/IneffectiveAccessModifier:
Lint/InheritException:
Description: 'Avoid inheriting from the `Exception` class.'
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.41'
VersionChanged: '<<next>>'
# The default base class in favour of `Exception`.
EnforcedStyle: runtime_error
SupportedStyles:
Expand Down
5 changes: 5 additions & 0 deletions lib/rubocop/cop/lint/inherit_exception.rb
Expand Up @@ -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
#
Expand Down

0 comments on commit bc9d310

Please sign in to comment.