Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#7842] Fix a false positive for Lint/RaiseException #7845

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#7842](https://github.com/rubocop-hq/rubocop/issues/7842): Fix a false positive for `Lint/RaiseException` when raising Exception with explicit namespace. ([@koic][])

## 0.81.0 (2020-04-01)

### New features
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/lint/raise_exception.rb
Expand Up @@ -16,12 +16,12 @@ class RaiseException < Cop
MSG = 'Use `StandardError` over `Exception`.'

def_node_matcher :exception?, <<~PATTERN
(send nil? ${:raise :fail} (const _ :Exception) ... )
(send nil? ${:raise :fail} (const {cbase nil?} :Exception) ... )
PATTERN

def_node_matcher :exception_new_with_message?, <<~PATTERN
(send nil? ${:raise :fail}
(send (const _ :Exception) :new ... ))
(send (const {cbase nil?} :Exception) :new ... ))
PATTERN

def on_send(node)
Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/lint/raise_exception_spec.rb
Expand Up @@ -80,4 +80,11 @@
it 'does not register an offense for `fail` without arguments' do
expect_no_offenses('fail')
end

it 'does not register an offense when raising Exception with explicit ' \
'namespace' do
expect_no_offenses(<<~RUBY)
raise Foo::Exception
RUBY
end
end