-
-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive when the receiver of all
is not an ActiveRecord object
#1124
Comments
all
is not an ActiveRecord object.all
is not an ActiveRecord object
Rubocop performs static analysis of the code (does not run the code), so there is no way to know if the receiver is a ActiveRecord model or not. And better the |
Isn't this code, which was introduced here determining whether it's an AR model? |
…rdAllMethod` Fixes rubocop#1124. This PR fixes false positives for `Rails/RedundantActiveRecordAllMethod` when receiver is not an Active Record model.
We encountered the same issue using |
@jorg-vr Since this cop is already marked as unsafe, there will be limited ways to prevent false positives for static analysis. Can you provide a specific code example where false positives occurs with |
Ah, I saw the backlink: That false positive could be resolved. |
On my end, I have two instances: one where I'm iterating over sidekiq queues and another where I'm calling an activehash-backed model. Neither of these inherit from def queue_too_latent?(queue_name, threshold_seconds)
queue = Sidekiq::Queue.all.find { |q| q.name == queue_name }
latency = queue&.latency || 0
latency > threshold_seconds
end Hazmat::SystemClassification.all.each do |sc|
…
end |
I haven't reviewed all cases for |
…dant_active_record_dll_method [Fix #1124] Fix false positives for `Rails/RedundantActiveRecordAllMethod`
As mentioned in this comment,
Rails/RedundantActiveRecordAllMethod
produces a false positive when the receiver ofall
is not an ActiveRecord object.Expected behavior
The cop should ignore cases where the receiver of
all
is not an ActiveRecord object.Actual behavior
Steps to reproduce the problem
Run rubocop on the following code:
$ bundle exec rubocop --only Rails/RedundantActiveRecordAllMethod ./app/false-positive.rb Inspecting 1 file C Offenses: app/false-positive.rb:2:25: C: [Correctable] Rails/RedundantActiveRecordAllMethod: Redundant all detected. ActiveSupport::TimeZone.all.first ^^^ app/false-positive.rb:3:23: C: [Correctable] Rails/RedundantActiveRecordAllMethod: Redundant all detected. ActionMailer::Preview.all.first ^^^
RuboCop version
The text was updated successfully, but these errors were encountered: