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

Cop idea: detect .none() #1034

Open
ydakuka opened this issue Jun 19, 2023 · 2 comments
Open

Cop idea: detect .none() #1034

ydakuka opened this issue Jun 19, 2023 · 2 comments

Comments

@ydakuka
Copy link

ydakuka commented Jun 19, 2023

Actual behavior

I have the code:

module ApplicationHelper
  def my_method
    User.where(id: nil)
    User.where(id: 0)
    User.where(id: [])
    User.where(id: {})
    User.limit(nil)
    User.limit(0)
  end
end

I run rubocop and don't get any offences:

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop app/helpers/application_helper.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Expected behavior

I expected to receive the following code:

module ApplicationHelper
  def my_method
    User.none # for all cases
  end
end
@koic
Copy link
Member

koic commented Jun 21, 2023

This seems to be a matter of style. Please open a proposal in the style guide first. If accepted there, it can be provided as a cop.
https://github.com/rubocop/rails-style-guide

Note that while these will return the same results in most cases, they do not behave strictly the same.

@ydakuka
Copy link
Author

ydakuka commented Jun 21, 2023

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

No branches or pull requests

2 participants