You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However I don't think this restriction is necessary, and I think it's actually unhelpful. I suspect that a large amount, perhaps the majority, of ActiveRecord .where usage would be found in controllers, not in models. In our application, it also crops up repeatedly in our tests.
Describe the solution you'd like
I'd like to see the default configuration updated, to remove the Include: ['app/models/**/*.rb'] restriction, for the Rails/FindBy and Rails/FindEach cops.
Describe alternatives you've considered
The alternative is for everyone to override the configuration for these two cops in their own configuration, e.g.
Rails/FindBy:
Include:
- '**/*.rb'
Additional context
The Include restriction was originally introduced alongside the initial cop (in rubocop) in 6188d755eefd94875bc155bbfe433f7752d0bd2b, but I can't find any related discussions.
The text was updated successfully, but these errors were encountered:
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Aug 2, 2023
…/FindEach`
Fixesrubocop#1058.
This PR relaxes `Include` path for `Rails/FindBy` and `Rails/FindEach`.
`Rails/FindBy` was introduced in rubocop/rubocop@6188d75.
This was before it was extracted to RuboCop Rails, which is probably why it was
targeting `app/models`. So, RuboCop Rails targeting Rails would not need it.
`Rails/FindEach` is the same:
rubocop/rubocop@f2e26812
Is your feature request related to a problem? Please describe.
I was trying to figure out why rubocop-rails wasn't picking up
where(...).first
usage in our application (OpenStreetMap).Eventually I found that the cop is restricted to models only, in the default configuration.
rubocop-rails/config/default.yml
Lines 461 to 469 in 34376e0
However I don't think this restriction is necessary, and I think it's actually unhelpful. I suspect that a large amount, perhaps the majority, of ActiveRecord
.where
usage would be found in controllers, not in models. In our application, it also crops up repeatedly in our tests.Describe the solution you'd like
I'd like to see the default configuration updated, to remove the
Include: ['app/models/**/*.rb']
restriction, for theRails/FindBy
andRails/FindEach
cops.Describe alternatives you've considered
The alternative is for everyone to override the configuration for these two cops in their own configuration, e.g.
Additional context
The
Include
restriction was originally introduced alongside the initial cop (in rubocop) in 6188d755eefd94875bc155bbfe433f7752d0bd2b, but I can't find any related discussions.The text was updated successfully, but these errors were encountered: