Skip to content

Commit

Permalink
[Fix #834] Fix an error for Rails/WhereNotWithMultipleConditions
Browse files Browse the repository at this point in the history
Fixes #834.

This PR fixes an error for `Rails/WhereNotWithMultipleConditions`
when using `where.not` with empty hash literal.
  • Loading branch information
koic committed Oct 25, 2022
1 parent 4058ce5 commit 8663b04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#834](https://github.com/rubocop/rubocop-rails/issues/834): Fix an error for `Rails/WhereNotWithMultipleConditions` when using `where.not` with empty hash literal. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def on_send(node)

def multiple_arguments_hash?(hash)
return true if hash.pairs.size >= 2
return false unless hash.values[0].hash_type?
return false unless hash.values[0]&.hash_type?

multiple_arguments_hash?(hash.values[0])
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@
User.where.not(trashed: true).where.not(role: 'admin')
RUBY
end

it 'does not register an offense for `where.not` with empty hash literal' do
expect_no_offenses(<<~RUBY)
User.where.not(data: {})
RUBY
end
end

0 comments on commit 8663b04

Please sign in to comment.