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

[Fix: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has any parameters #1114

Conversation

masato-bkn
Copy link
Contributor

@masato-bkn masato-bkn commented Sep 11, 2023

Resolved the following issue: #1110
As pointed out in the mentioned issue, there was an oversight. I apologize for the mistake.

In this PR, the cop treats all with parameters as not being an ActiveRecord method and excludes it from offenses.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • [ ] If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@masato-bkn masato-bkn changed the title Fix/rails redundant active record all when all has arguments [FIx: #1110] redundant active record all when all has arguments Sep 11, 2023
@masato-bkn masato-bkn force-pushed the fix/rails_redundant_active_record_all_when_all_has_arguments branch 2 times, most recently from aa29805 to 0dcbf2b Compare September 11, 2023 16:21
@masato-bkn masato-bkn marked this pull request as ready for review September 11, 2023 16:30
@masato-bkn masato-bkn changed the title [FIx: #1110] redundant active record all when all has arguments [FIx: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has arguments Sep 11, 2023
@masato-bkn masato-bkn changed the title [FIx: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has arguments [Fix: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has arguments Sep 11, 2023
@masato-bkn masato-bkn force-pushed the fix/rails_redundant_active_record_all_when_all_has_arguments branch from 0dcbf2b to f0b27f9 Compare September 11, 2023 17:24
@masato-bkn masato-bkn changed the title [Fix: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has arguments [Fix: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has parameters Sep 11, 2023
@masato-bkn masato-bkn changed the title [Fix: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has parameters [Fix: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has any parameters Sep 11, 2023
@masato-bkn masato-bkn force-pushed the fix/rails_redundant_active_record_all_when_all_has_arguments branch 2 times, most recently from 90620b1 to b573569 Compare September 11, 2023 17:52
@@ -260,6 +260,26 @@
RUBY
end
end

context 'when `all` has any parameters (indicating it is not an Active Record `all`)' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tweak the text?

Suggested change
context 'when `all` has any parameters (indicating it is not an Active Record `all`)' do
context 'when `all` has any parameters, it indicates that it is not an Active Record `all`' do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. I've updated the context name.

…rdAllMethod` when `all` has any parameters
@masato-bkn masato-bkn force-pushed the fix/rails_redundant_active_record_all_when_all_has_arguments branch from b573569 to a731016 Compare September 12, 2023 18:28
@koic koic merged commit a56fb0e into rubocop:master Sep 12, 2023
4 checks passed
@koic
Copy link
Member

koic commented Sep 12, 2023

Thanks!

@eneagoe
Copy link

eneagoe commented Sep 18, 2023

I'm afraid this doesn't fix all false positives. An example wold be

ActiveSupport::TimeZone.all.find { |tz| tz.tzinfo.utc_offset == 32400 }

@masato-bkn
Copy link
Contributor Author

@eneagoe
Thank you for your report! I've created an issue.

koic added a commit to koic/rubocop-rails that referenced this pull request Sep 19, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `RedundantActiveRecordAllMethod`
when using `find` with block argument.

`Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
koic added a commit to koic/rubocop-rails that referenced this pull request Sep 19, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `RedundantActiveRecordAllMethod`
when using `find` with block argument.

`Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
koic added a commit to koic/rubocop-rails that referenced this pull request Sep 19, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `RedundantActiveRecordAllMethod`
when using `find` with block argument.

`Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
koic added a commit to koic/rubocop-rails that referenced this pull request Sep 19, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `RedundantActiveRecordAllMethod`
when using `find` with block argument.

`Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
koic added a commit to koic/rubocop-rails that referenced this pull request Sep 19, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `Rails/RedundantActiveRecordAllMethod`
when using `find` with block argument.

`Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
koic added a commit to koic/rubocop-rails that referenced this pull request Sep 20, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `Rails/RedundantActiveRecordAllMethod`
when using `Enumerable`'s methods with block argument.

`Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
koic added a commit to koic/rubocop-rails that referenced this pull request Sep 20, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `Rails/RedundantActiveRecordAllMethod`
when using some `Enumerable`'s methods with block argument.

`Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
koic added a commit to koic/rubocop-rails that referenced this pull request Sep 25, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `Rails/RedundantActiveRecordAllMethod`
when using some `Enumerable`'s methods with block argument.

e.g. `Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
koic added a commit to koic/rubocop-rails that referenced this pull request Sep 28, 2023
Resolves rubocop#1114 (comment)

This PR fixes a false positive for `Rails/RedundantActiveRecordAllMethod`
when using some `Enumerable`'s methods with block argument.

e.g. `Enumerable#find` and `ActiveRecord::Base#find` have different arguments,
So false positives can be prevented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants