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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1382](https://github.com/rubocop/rubocop-rails/pull/1382): Fix false negatives for `Rails/RedundantActiveRecordAllMethod` when using `all` method in block. ([@masato-bkn][])
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def possible_enumerable_block_method?(node)
parent = node.parent
return false unless POSSIBLE_ENUMERABLE_BLOCK_METHODS.include?(parent.method_name)

parent.parent&.block_type? || parent.parent&.numblock_type? || parent.first_argument&.block_pass_type?
parent.block_literal? || parent.first_argument&.block_pass_type?
end

def sensitive_association_method?(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@
User.all.#{method}(&:do_something)
RUBY
end

it "registers an offense when using `#{method}` in block" do
expect_offense(<<~RUBY)
do_something { User.all.#{method} }
^^^ Redundant `all` detected.
RUBY
end
end
end

Expand Down