diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c40f31afbe..73f0af0dff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * [#8406](https://github.com/rubocop-hq/rubocop/issues/8406): Improve `Style/AccessorGrouping`'s auto-correction to remove redundant blank lines. ([@koic][]) * [#8330](https://github.com/rubocop-hq/rubocop/issues/8330): Fix a false positive for `Style/MissingRespondToMissing` when defined method with inline access modifier. ([@koic][]) * [#8422](https://github.com/rubocop-hq/rubocop/issues/8422): Fix an error for `Lint/SelfAssignment` when using or-assignment for constant. ([@koic][]) +* [#8423](https://github.com/rubocop-hq/rubocop/issues/8423): Fix an error for `Style/SingleArgumentDig` when without a receiver. ([@koic][]) ### Changes diff --git a/lib/rubocop/cop/style/single_argument_dig.rb b/lib/rubocop/cop/style/single_argument_dig.rb index da86a0bdb7d..de975d439d0 100644 --- a/lib/rubocop/cop/style/single_argument_dig.rb +++ b/lib/rubocop/cop/style/single_argument_dig.rb @@ -33,6 +33,8 @@ class SingleArgumentDig < Base PATTERN def on_send(node) + return unless node.receiver + expression = single_argument_dig?(node) return unless expression diff --git a/spec/rubocop/cop/style/single_argument_dig_spec.rb b/spec/rubocop/cop/style/single_argument_dig_spec.rb index 6362c5479f5..7e466ac60ac 100644 --- a/spec/rubocop/cop/style/single_argument_dig_spec.rb +++ b/spec/rubocop/cop/style/single_argument_dig_spec.rb @@ -66,4 +66,12 @@ end end end + + context 'when without a receiver' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + dig(:key) + RUBY + end + end end