-
-
Notifications
You must be signed in to change notification settings - Fork 87
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Expected behavior
RuboCop suggests valid corrections on arrays.
Actual behavior
Identifies multiple uses of ActiveRecord query select
method
While calling select
multiple times on the same relation may technically be redundant, this is a completely distinct method from Array.select
, and thus suggesting to use select!
(which does not exist), should not happen.
Steps to reproduce the problem
Run rubocop on this file with Performance/ChainArrayAllocation
enabled
models/test.rb
class Test < ActiveRecord::Base
scope :test_scope, -> {
select(:field_one, :field_two).
select("COUNT(DISTINCT(tests.field_three)) AS num").
where("tests.field_one IS NOT NULL").
group(:field_two)
}
def self.something
Test.all
.select(:field_one, :field_two)
.select("COUNT(DISTINCT(tests.field_three)) AS num")
.where("tests.field_one IS NOT NULL")
.group(:field_two)
end
end
RuboCop version
Found on version
1.31.0 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 2.7.8 x86_64-darwin21)
- rubocop-performance 1.19.1
- rubocop-rails 2.15.2
Still occurs on latest
1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 2.7.8) [x86_64-darwin21]
- rubocop-performance 1.20.2
- rubocop-rails 2.23.1
Perhaps this is why this cop is disabled by default, because it has these are unsolvable false positives?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working