rubocop-rails
rubocop-rails copied to clipboard
[Fix #565] Add cop Rails/WhereNotWithMultipleConditions
Rails 6.1 changed how where.not works with multiple hash arguments.
This cop identifies places where where.not is used with multiple hash arguments. It doesn't suggest corrections because depending on the rails version, different behaviours may be correct.
# bad
User.where.not(trashed: true, role: 'admin')
# good
User.where.not('trashed = ? OR role = ?', true, 'admin')
Before submitting the PR make sure the following are checked:
- [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
- [x] Wrote good commit messages.
- [x] Commit message starts with
[Fix #issue-number]
(if the related issue exists). - [x] Feature branch is up-to-date with
master
(if not - rebase it). - [x] Squashed related commits together.
- [x] Added tests.
- [x] Ran
bundle exec rake default
. It executes all tests and runs RuboCop on its own code. - [x] Added an entry (file) to the changelog folder named
{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details. - [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
- [ ] If this is a new cop, consider making a corresponding update to the Rails Style Guide - PR: rubocop/rails-style-guide/pull/296
It doesn't suggest corrections because depending on the rails version, different behaviours may be correct.
Yeah, I agree with the incompatible behavior, but I think this cop can provide unsafe auto-correction.
Let's also update the PR title so it shows up when people search for WhereNotWithMultipleConditions
.
@andyw8 @koic Can one of you have another review for this PR or is it already ready for a merge to master? Thanks!
@niklas-hasselmeyer I'm sorry for delay. This looks good to me. Can you squash your commits into one?
@koic I squashed my commits and rebased on master, so this can be merged
Thanks!