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

New Cop idea: detect redundant all #1016

Closed
masato-bkn opened this issue Jun 10, 2023 · 2 comments · Fixed by #1020
Closed

New Cop idea: detect redundant all #1016

masato-bkn opened this issue Jun 10, 2023 · 2 comments · Fixed by #1020

Comments

@masato-bkn
Copy link
Contributor

masato-bkn commented Jun 10, 2023

Is your feature request related to a problem? Please describe.

I often come across all used as receiver for Active Record query methods

User.all.order(:created_at)
User.all.find(id)

However, in these cases, the output is the same with or without all, so I think it's redundant and could be removed.

Describe the solution you'd like

I'd like to add a cop that remove all used as receiver of Active Record query methods.

Example

# bad
User.all.order(:created_at)
User.all.find(id)

# good
User.order(:created_at)
User.find(id)

Query methods to be checked

I am considering one of the following options for methods to be checked by this cop.

Additional context

If there's a positive reaction to this cop idea, I plan to submit a PR.

@masato-bkn masato-bkn changed the title New Cop idea: Rails/RedundantAll New Cop idea: detect redundant all Jun 10, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Jun 17, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Jun 17, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Jun 17, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Jun 17, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Jun 18, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Aug 11, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Aug 11, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Aug 11, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Aug 27, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Aug 27, 2023
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Aug 27, 2023
koic added a commit that referenced this issue Aug 28, 2023
[Fix #1016] Add `Rails/RedundantActiveRecordAllMethod` cop
@mkllnk
Copy link

mkllnk commented Sep 11, 2023

The release notes list this as bug fix but it should have been a new feature, right?

@koic
Copy link
Member

koic commented Sep 11, 2023

@mkllnk I've fixed the incorrect entry in this commit: 3932c01 Thanks!

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 a pull request may close this issue.

3 participants