Skip to content

Commit

Permalink
[Fix rubocop#7052] Make Lint/HandleExceptions register offense for …
Browse files Browse the repository at this point in the history
…rescue nil
  • Loading branch information
tejasbubane committed Aug 20, 2019
1 parent bd54a4c commit 8e686ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* [#7274](https://github.com/rubocop-hq/rubocop/issues/7274): Add new `Lint/SendWithMixinArgument` cop. ([@koic][])
* [#7272](https://github.com/rubocop-hq/rubocop/pull/7272): Show warning message if passed string to `Enabled`, `Safe`, `SafeAutocorrect`, and `AutoCorrect` keys in .rubocop.yml. ([@unasuke][])
* [#7295](https://github.com/rubocop-hq/rubocop/pull/7295): Make it possible to set `StyleGuideBaseURL` per department. ([@koic][])
* [#7052](https://github.com/rubocop-hq/rubocop/issues/7052): Make `Lint/HandleExceptions` register offense for rescue nil. ([@tejasbubane][])

### Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/handle_exceptions.rb
Expand Up @@ -78,7 +78,7 @@ class HandleExceptions < Cop
MSG = 'Do not suppress exceptions.'

def on_resbody(node)
return if node.body
return if node.body && !node.body.nil_type?
return if cop_config['AllowComments'] && comment_lines?(node)

add_offense(node)
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/lint/handle_exceptions_spec.rb
Expand Up @@ -14,6 +14,24 @@
RUBY
end

it 'registers an offense for rescue nil' do
expect_offense(<<~RUBY)
begin
something
rescue
^^^^^^ Do not suppress exceptions.
nil
end
RUBY
end

it 'registers an offense for inline nil rescue' do
expect_offense(<<~RUBY)
something rescue nil
^^^^^^^^^^ Do not suppress exceptions.
RUBY
end

it 'does not register an offense for rescue with body' do
expect_no_offenses(<<~RUBY)
begin
Expand Down

0 comments on commit 8e686ba

Please sign in to comment.