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

False positive for Rails/RedundantActiveRecordAllMethod cop in 2.21.0 #1110

Closed
mkllnk opened this issue Sep 11, 2023 · 2 comments
Closed

False positive for Rails/RedundantActiveRecordAllMethod cop in 2.21.0 #1110

mkllnk opened this issue Sep 11, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@mkllnk
Copy link

mkllnk commented Sep 11, 2023

The cop is detecting calls to all on any object, not just ActiveRecord models. Using RSpec and Capybara, it can be useful to write code like:

page.all("button").select(&custom_filter).first.click

This is detected by the cop even though all and first do not refer to ActiveRecord methods.


Expected behavior

The cop should only complain about ActiveRecord's all method.

Actual behavior

spec/system/consumer/shopping/shopping_spec.rb:564:20: C: [Correctable] Rails/RedundantActiveRecordAllMethod: Redundant all detected.
              page.all("button", text: increase_quantity_symbol).last.click
                   ^^^

Steps to reproduce the problem

echo '
describe "failing cop", type: :system do
  it "detects Capybara calls" do
    page.all("button").first
  end
end
' > example_spec.rb

rubocop example_spec.rb

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You can see extension cop versions (e.g. rubocop-rails, rubocop-performance, and others) output by rubocop -V,
include them as well. Here's an example:

$ [bundle exec] rubocop -V
1.56.2 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.4) [x86_64-linux]
  - rubocop-rails 2.21.0
@franzliedke
Copy link

all with parameters should probably be excluded. The auto-correction also causes syntax errors in these cases.

masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 11, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 11, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 11, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 11, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 11, 2023
…rdAllMethod` when `all` has any parameters
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 11, 2023
…rdAllMethod` when `all` has any parameters
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 11, 2023
…rdAllMethod` when `all` has any parameters
@koic koic closed this as completed in a731016 Sep 12, 2023
koic added a commit that referenced this issue Sep 12, 2023
…ecord_all_when_all_has_arguments

[Fix: #1110] Fix false positive for `Rails/RedundantActiveRecordAllMethod` when `all` has any parameters
@mkllnk
Copy link
Author

mkllnk commented Sep 12, 2023

Thank you for the quick fix!

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

No branches or pull requests

3 participants