Skip to content

Commit

Permalink
[Fix rubocop#8423] Fix an error for Style/SingleArgumentDig
Browse files Browse the repository at this point in the history
Fixes rubocop#8423.

This PR fixes an error for `Style/SingleArgumentDig`
when without a receiver.
This cop wouldn't have to offense when `dig` method without a receiver.
  • Loading branch information
koic committed Jul 31, 2020
1 parent c343832 commit cb751c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/style/single_argument_dig.rb
Expand Up @@ -33,6 +33,8 @@ class SingleArgumentDig < Base
PATTERN

def on_send(node)
return unless node.receiver

expression = single_argument_dig?(node)
return unless expression

Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/style/single_argument_dig_spec.rb
Expand Up @@ -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

0 comments on commit cb751c0

Please sign in to comment.