diff --git a/lib/rubocop/cop/lint/safe_navigation_with_empty.rb b/lib/rubocop/cop/lint/safe_navigation_with_empty.rb index c4fbfd0168a..530684492ad 100644 --- a/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +++ b/lib/rubocop/cop/lint/safe_navigation_with_empty.rb @@ -30,7 +30,7 @@ class SafeNavigationWithEmpty < Cop def on_if(node) return unless safe_navigation_empty_in_conditional?(node) - add_offense(node) + add_offense(node.condition) end end end diff --git a/spec/rubocop/cop/lint/safe_navigation_with_empty_spec.rb b/spec/rubocop/cop/lint/safe_navigation_with_empty_spec.rb index cec0ea6c4cd..2f7688fbc07 100644 --- a/spec/rubocop/cop/lint/safe_navigation_with_empty_spec.rb +++ b/spec/rubocop/cop/lint/safe_navigation_with_empty_spec.rb @@ -7,7 +7,7 @@ it 'registers an offense on `&.empty?`' do expect_offense(<<~RUBY) return unless foo&.empty? - ^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `empty?` with the safe navigation operator in conditionals. + ^^^^^^^^^^^ Avoid calling `empty?` with the safe navigation operator in conditionals. RUBY end