Skip to content

Commit

Permalink
Merge pull request #10576 from ydah/fix_single_argment_dig
Browse files Browse the repository at this point in the history
[Fix #10574] Fix a false positive for `Style/SingleArgumentDig`
  • Loading branch information
koic committed Apr 23, 2022
2 parents a331f43 + dd8bf68 commit df09f42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_a_false_positive_for_single_argment_dig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#10574](https://github.com/rubocop/rubocop/issues/10574): Fix a false positive for `Style/SingleArgumentDig` when using dig with arguments forwarding. ([@ydah][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/single_argument_dig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def on_send(node)

expression = single_argument_dig?(node)
return unless expression
return if expression.forwarded_args_type?

receiver = node.receiver.source
argument = expression.source
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/style/single_argument_dig_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
end
end

context '>= Ruby 2.7', :ruby27 do
context 'when using dig with arguments forwarding' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
def foo(...)
{ key: 'value' }.dig(...)
end
RUBY
end
end
end

describe 'dig over a variable as caller' do
context 'with single argument' do
it 'registers an offense and corrects unsuitable use of dig' do
Expand Down

0 comments on commit df09f42

Please sign in to comment.