Skip to content

Commit

Permalink
[Fix #11631] Fix an incorrect autocorrect for `Style/ArgumentsForward…
Browse files Browse the repository at this point in the history
…ing`

Fixes #11631.

This PR fixes an incorrect autocorrect for `Style/ArgumentsForwarding`
when using arguments forwarding for `.()` call.
  • Loading branch information
koic authored and bbatsov committed Feb 26, 2023
1 parent 6ba66be commit 999ac27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11631](https://github.com/rubocop/rubocop/issues/11631): Fix an incorrect autocorrect for `Style/ArgumentsForwarding` when using arguments forwarding for `.()` call. ([@koic][])
6 changes: 3 additions & 3 deletions lib/rubocop/cop/style/arguments_forwarding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def all_lvars_as_forwarding_method_arguments?(def_node, forwarding_method)

def register_offense_to_forwarding_method_arguments(forwarding_method)
add_offense(arguments_range(forwarding_method)) do |corrector|
range = range_between(
forwarding_method.loc.selector.end_pos, forwarding_method.source_range.end_pos
)
begin_pos = forwarding_method.loc.selector&.end_pos || forwarding_method.loc.dot.end_pos
range = range_between(begin_pos, forwarding_method.source_range.end_pos)

corrector.replace(range, '(...)')
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/style/arguments_forwarding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ def foo(*args, &block)
RUBY
end

it 'registers an offense when using restarg and block arg for `.()` call' do
expect_offense(<<~RUBY)
def foo(*args, &block)
^^^^^^^^^^^^^ Use arguments forwarding.
bar.(*args, &block)
^^^^^^^^^^^^^ Use arguments forwarding.
end
RUBY

expect_correction(<<~RUBY)
def foo(...)
bar.(...)
end
RUBY
end

it 'does not register an offense when using arguments forwarding' do
expect_no_offenses(<<~RUBY)
def foo(...)
Expand Down

0 comments on commit 999ac27

Please sign in to comment.