Skip to content

[experimental] Custom cop for detecting missing select#227

Draft
andyatkinson wants to merge 1 commit intomainfrom
chore/rubocop-detect-missing-select
Draft

[experimental] Custom cop for detecting missing select#227
andyatkinson wants to merge 1 commit intomainfrom
chore/rubocop-detect-missing-select

Conversation

@andyatkinson
Copy link
Owner

@andyatkinson andyatkinson commented May 28, 2025

An explicit select clause, e.g. select(:id), could be a better way to
get started to embrace a "restrictive by default" approach

This could be set up to require no bare Model.all etc. without an
explicit select clause and a list of fields

Putting in examples like Trip.where(id: 1) in a file, running Rubocop for that file:

bundle exec rubocop app/controllers/api/trip_requests_controller.rb

app/controllers/api/trip_requests_controller.rb:20:5: C: [Correctable] \
  Custom/ExplicitSelect: Avoid using where without an explicit .select(...). \
  Autocorrecting to .select(:id).

@andyatkinson
Copy link
Owner Author

GitLab Rails Rubocop that I like:

Should probably add pluck()

An explicit select clause, e.g. select(:id), could be a better way to
get started to embrace a "restrictive by default" approach

This could be set up to require no bare Model.all etc. without an
explicit select clause and a list of fields
@andyatkinson andyatkinson force-pushed the chore/rubocop-detect-missing-select branch from a7f9dad to d71e4fa Compare June 12, 2025 20:53
@andyatkinson andyatkinson changed the title Custom cop for detecting missing select [experimental] Custom cop for detecting missing select Jul 1, 2025
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.

1 participant