Skip to content

Commit

Permalink
[Fix #9613] Fix a false positive for Style/RedundantSelf
Browse files Browse the repository at this point in the history
Fixes #9613.

This PR fixes a false positive for `Style/RedundantSelf`
when a self receiver on an lvalue of mlhs arguments.
  • Loading branch information
koic authored and bbatsov committed Mar 19, 2021
1 parent 709e5ee commit f4fe4c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
@@ -0,0 +1 @@
* [#9613](https://github.com/rubocop/rubocop/issues/9613): Fix a false positive for `Style/RedundantSelf` when a self receiver on an lvalue of mlhs arguments. ([@koic][])
8 changes: 6 additions & 2 deletions lib/rubocop/cop/style/redundant_self.rb
Expand Up @@ -144,8 +144,12 @@ def regular_method_call?(node)
end

def on_argument(node)
name, = *node
@local_variables_scopes[node] << name
if node.mlhs_type?
on_args(node)
else
name, = *node
@local_variables_scopes[node] << name
end
end

def allow_self(node)
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/style/redundant_self_spec.rb
Expand Up @@ -234,4 +234,13 @@ def self.requested_specs
it 'accepts a self receiver of methods also defined on `Kernel`' do
expect_no_offenses('self.open')
end

it 'accepts a self receiver on an lvalue of mlhs arguments' do
expect_no_offenses(<<~RUBY)
def do_something((a, b)) # This method expects Array that has 2 elements as argument.
self.a = a
self.b.some_method_call b
end
RUBY
end
end

0 comments on commit f4fe4c9

Please sign in to comment.