Skip to content

Commit a250bfa

Browse files
authoredFeb 28, 2025
Merge pull request #1459 from Earlopain/uniq-before-pluck-numblock
Fix a false positive for `Rails/UniqBeforePluck` when using a numblock with `uniq`
2 parents 67cff82 + 78988e7 commit a250bfa

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1459](https://github.com/rubocop/rubocop-rails/pull/1459): Fix a false positive for `Rails/UniqBeforePluck` when using a numblock with `uniq`. ([@earlopain][])

‎lib/rubocop/cop/rails/uniq_before_pluck.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class UniqBeforePluck < Base
5252
MSG = 'Use `distinct` before `pluck`.'
5353
RESTRICT_ON_SEND = %i[uniq].freeze
5454

55-
def_node_matcher :uniq_before_pluck, '[!^block $(send $(send _ :pluck ...) :uniq ...)]'
55+
def_node_matcher :uniq_before_pluck, '[!^any_block $(send $(send _ :pluck ...) :uniq ...)]'
5656

5757
def on_send(node)
5858
uniq_before_pluck(node) do |uniq_node, pluck_node|

‎spec/rubocop/cop/rails/uniq_before_pluck_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
Model.where(foo: 1).pluck(:name).uniq { |k| k[0] }
7575
RUBY
7676
end
77+
78+
it 'ignores uniq with a numblock' do
79+
expect_no_offenses(<<~RUBY)
80+
Model.where(foo: 1).pluck(:name).uniq { _1[0] }
81+
RUBY
82+
end
7783
end
7884

7985
it 'registers an offense' do

0 commit comments

Comments
 (0)