Skip to content
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

Rails/FindEach: false positive on ActiveModel::Errors on Rails 6.1 #551

Closed
colinux opened this issue Sep 16, 2021 · 0 comments · Fixed by #552
Closed

Rails/FindEach: false positive on ActiveModel::Errors on Rails 6.1 #551

colinux opened this issue Sep 16, 2021 · 0 comments · Fixed by #552
Labels
bug Something isn't working

Comments

@colinux
Copy link

colinux commented Sep 16, 2021

rubocop-rails raises a false positive Rails/FindEach on ActiveModel errors slice from the new query interface introduced in Rails 6.1.

Model.new.errors.where(:title).each {   }
                               ^^^^ Use find_each instead of each

Expected behavior

Rails/FindEach should ignore ActiveModel::Errors class.

Actual behavior

Considers ActiveModel::Errors as an ActiveRecord model, triggering a false positive offense

Steps to reproduce the problem

See above minimal example on Rails 6.1.

RuboCop version

$  bundle exec rubocop -V
1.21.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 2.6.6 x86_64-darwin19)
  - rubocop-minitest 0.15.0
  - rubocop-performance 1.11.5
  - rubocop-rails 2.12.2
  - rubocop-rake 0.6.0
@koic koic added the bug Something isn't working label Sep 17, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Sep 17, 2021
Fixes rubocop#551.

This PR fixes a false positive for `Rails/FindEach`
when using `model.errors.where` in Rails 6.1.
@koic koic closed this as completed in #552 Sep 25, 2021
koic added a commit that referenced this issue Sep 25, 2021
…_each

[Fix #551] Fix a false positive for `Rails/FindEach`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants