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

handle exception in Rails/RedundantReceiverInWithOptions with empty body #6855

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,9 @@

## master (unreleased)

### Bug fixes
* [#6855](https://github.com/rubocop-hq/rubocop/pull/6855): Fix an exception in `Rails/RedundantReceiverInWithOptions` when the body is empty. ([@ericsullivan][])

### Changes

* [#5977](https://github.com/rubocop-hq/rubocop/issues/5977): Warn for Performance Cops. ([@koic][])
Expand Down Expand Up @@ -3882,3 +3885,4 @@
[@elmasantos]: https://github.com/elmasantos
[@luciamo]: https://github.com/luciamo
[@dirtyharrycallahan]: https://github.com/dirtyharrycallahan
[@ericsullivan]: https://github.com/ericsullivan
Expand Up @@ -81,6 +81,7 @@ class RedundantReceiverInWithOptions < Cop

def on_block(node)
with_options?(node) do |arg, body|
return if body.nil?
return unless all_block_nodes_in(body).count.zero?

send_nodes = all_send_nodes_in(body)
Expand Down
Expand Up @@ -87,12 +87,20 @@ class Account < ApplicationRecord
end
RUBY
end

it 'does not register an offense when empty' do
expect_no_offenses(<<-RUBY.strip_indent)
with_options options: false do |merger|
end
RUBY
end
end

context 'rails <= 4.1' do
let(:rails_version) { 4.1 }

it 'registers an offense when using explicit receiver in `with_options`' do
it 'does not register an offense when using explicit receiver in ' \
'`with_options`' do
expect_no_offenses(<<-RUBY.strip_indent)
class Account < ApplicationRecord
with_options dependent: :destroy do |assoc|
Expand Down