Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #9613] Fix a false positive for Style/RedundantSelf #9614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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