Skip to content

Commit 8663b04

Browse files
committed
[Fix rubocop#834] Fix an error for Rails/WhereNotWithMultipleConditions
Fixes rubocop#834. This PR fixes an error for `Rails/WhereNotWithMultipleConditions` when using `where.not` with empty hash literal.
1 parent 4058ce5 commit 8663b04

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def on_send(node)
4545

4646
def multiple_arguments_hash?(hash)
4747
return true if hash.pairs.size >= 2
48-
return false unless hash.values[0].hash_type?
48+
return false unless hash.values[0]&.hash_type?
4949

5050
multiple_arguments_hash?(hash.values[0])
5151
end

spec/rubocop/cop/rails/where_not_with_multiple_conditions_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@
4444
User.where.not(trashed: true).where.not(role: 'admin')
4545
RUBY
4646
end
47+
48+
it 'does not register an offense for `where.not` with empty hash literal' do
49+
expect_no_offenses(<<~RUBY)
50+
User.where.not(data: {})
51+
RUBY
52+
end
4753
end

0 commit comments

Comments
 (0)