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

Add new Rails/PluckId cop #272

Merged
merged 1 commit into from
Jul 6, 2020
Merged

Add new Rails/PluckId cop #272

merged 1 commit into from
Jul 6, 2020

Conversation

fatkodima
Copy link
Contributor

@fatkodima
Copy link
Contributor Author

Updated.

@koic
Copy link
Member

koic commented Jul 6, 2020

Is it as expected to prioritize this Rails/PluckId cop over Rails/PluckInWhere cop when using auto-correction?

% cat app/models/example.rb
class Foo < ApplicationRecord
  def bar
    Bar.where(baz_id: Baz.pluck(:id))
  end
end
% bundle exec rubocop app/models/example.rb -A --only Rails/PluckInWhere,Rails/PluckId
(snip)

Inspecting 1 file
C

Offenses:

app/models/example.rb:3:27: C: [Corrected] Rails/PluckId: Use ids instead of pluck(:id).
    Bar.where(baz_id: Baz.pluck(:id))
                          ^^^^^^^^^^
app/models/example.rb:3:27: C: [Corrected] Rails/PluckInWhere: Use select instead of pluck within where query method.
    Bar.where(baz_id: Baz.pluck(:id))
                          ^^^^^

1 file inspected, 2 offenses detected, 2 offenses corrected
% cat app/models/example.rb
class Foo < ApplicationRecord
  def bar
    Bar.where(baz_id: Baz.ids)
  end
end

@fatkodima
Copy link
Contributor Author

Thanks! This is not expected. Updated the code to check if in where and added a test case for this.

@fatkodima
Copy link
Contributor Author

Updated.

@koic koic merged commit 78c30d1 into rubocop:master Jul 6, 2020
@koic
Copy link
Member

koic commented Jul 6, 2020

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 this pull request may close these issues.

2 participants