Skip to content

Commit

Permalink
Merge pull request #1382 from masato-bkn/fix-redundant_active_record_…
Browse files Browse the repository at this point in the history
…all_method

Fix false negatives for `Rails/RedundantActiveRecordAllMethod` when using `POSSIBLE_ENUMERABLE_BLOCK_METHODS` in a block
  • Loading branch information
koic authored Oct 29, 2024
2 parents 1d7f0c4 + 2d7e7a0 commit ad3287a
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 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

0 comments on commit ad3287a

Please sign in to comment.