Skip to content

Commit

Permalink
[Fix #8008] Fix an error for Lint/SuppressedException
Browse files Browse the repository at this point in the history
Fixes #8008.

This PR fixes an error for `Lint/SuppressedException`
when empty rescue block in `def`.
  • Loading branch information
koic authored and bbatsov committed May 22, 2020
1 parent a29e2ce commit ebc19ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#8008](https://github.com/rubocop-hq/rubocop/issues/8008): Fix an error for `Lint/SuppressedException` when empty rescue block in `def`. ([@koic][])

## 0.84.0 (2020-05-21)

### New features
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/lint/suppressed_exception.rb
Expand Up @@ -82,6 +82,8 @@ def comment_between_rescue_and_end?(node)
end_line = ancestor.loc.end.line
break
end
return false unless end_line

processed_source[node.first_line...end_line].any? { |line| comment_line?(line) }
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/lint/suppressed_exception_spec.rb
Expand Up @@ -41,6 +41,16 @@
RUBY
end

it 'registers an offense for empty rescue block in `def`' do
expect_offense(<<~RUBY)
def foo
do_something
rescue
^^^^^^ Do not suppress exceptions.
end
RUBY
end

it 'registers an offense for empty rescue on single line with a comment after it' do
expect_offense(<<~RUBY)
RSpec.describe Dummy do
Expand Down

0 comments on commit ebc19ad

Please sign in to comment.