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 reports issue on any class #103

Closed
Korri opened this issue Aug 12, 2019 · 0 comments · Fixed by #464
Closed

Rails/FindEach reports issue on any class #103

Korri opened this issue Aug 12, 2019 · 0 comments · Fixed by #464
Labels
bug Something isn't working

Comments

@Korri
Copy link

Korri commented Aug 12, 2019

Right now every instance of all.each on any class and report is as a violation by Rails/FindEach.

This is particularly with classes that only include part of ActiveRecord like https://github.com/byroot/frozen_record for example.

Expected behavior

The following class should pass validation, as this class does not includes ActiveRecord::Batches and does not support find_each.

# frozen_string_literal: true

# Example class
class TestClass
  all.each { |a| do_something a.name }
end

Actual behavior

Offenses:

app/models/test_class.rb:5:7: C: Rails/FindEach: Use find_each instead of each.
  all.each { |a| add a.name }
      ^^^^

Steps to reproduce the problem

Using the example above should be enough.

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ [bundle exec] rubocop -V
0.74.0 (using Parser 2.6.3.0, running on ruby 2.3.7 universal.x86_64-darwin18)
@Korri Korri changed the title Rails/FindEach should check that class implements ActiveRecord::Batches Rails/FindEach reports issue on any class ActiveRecord::Batches Aug 12, 2019
@Korri Korri changed the title Rails/FindEach reports issue on any class ActiveRecord::Batches Rails/FindEach reports issue on any class Aug 12, 2019
@koic koic added the bug Something isn't working label Apr 24, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Apr 26, 2021
Fixes rubocop#103.

This PR fixes a false positive for `Rails/FindEach`
when not inheriting `ActiveRecord::Base` and using `all.each`.
@koic koic closed this as completed in #464 Apr 26, 2021
koic added a commit that referenced this issue Apr 26, 2021
[Fix #103] 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