Skip to content

Commit

Permalink
Fix false negatives for Rails/RedundantActiveRecordAllMethod when m…
Browse files Browse the repository at this point in the history
…ethods in `POSSIBLE_ENUMERABLE_BLOCK_METHODS` are used in a block.
  • Loading branch information
masato-bkn committed Oct 27, 2024
1 parent 1d7f0c4 commit a97f810
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
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 methods in `POSSIBLE_ENUMERABLE_BLOCK_METHODS` are used in a 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_node || 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

0 comments on commit a97f810

Please sign in to comment.