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 false positive in Style/RedundantSelf cop with nested self access #8585

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -77,6 +77,7 @@
* [#8518](https://github.com/rubocop-hq/rubocop/issues/8518): Fix `Lint/ConstantResolution` cop reporting offense for `module` and `class` definitions. ([@tejasbubane][])
* [#8158](https://github.com/rubocop-hq/rubocop/issues/8158): Fix `Style/MultilineWhenThen` cop to correctly handle cases with multiline body. ([@dsavochkin][])
* [#7705](https://github.com/rubocop-hq/rubocop/issues/7705): Fix `Style/OneLineConditional` cop to handle if/then/elsif/then/else/end cases. Add `AlwaysCorrectToMultiline` config option to this cop to always convert offenses to the multi-line form (false by default). ([@Lykos][], [@dsavochkin][])
* [#8585](https://github.com/rubocop-hq/rubocop/pull/8585): Fix false positive in `Style/RedundantSelf` cop with nested `self` access. ([@marcotc][])
* [#8590](https://github.com/rubocop-hq/rubocop/issues/8590): Fix an error when auto-correcting encoding mismatch file. ([@koic][])
* [#8321](https://github.com/rubocop-hq/rubocop/issues/8321): Enable auto-correction for `Layout/{Def}EndAlignment`, `Lint/EmptyEnsure`, `Style/ClassAndModuleChildren`. ([@marcandre][])
* [#8583](https://github.com/rubocop-hq/rubocop/issues/8583): Fix `Style/RedundantRegexpEscape` false positive for line continuations. ([@owst][])
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/style/redundant_self.rb
Expand Up @@ -131,6 +131,9 @@ def add_scope(node, local_variables = [])
def allowed_send_node?(node)
@allowed_send_nodes.include?(node) ||
@local_variables_scopes[node].include?(node.method_name) ||
node.each_ancestor.any? do |ancestor|
@local_variables_scopes[ancestor].include?(node.method_name)
end ||
KERNEL_METHODS.include?(node.method_name)
end

Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/style/redundant_self_spec.rb
Expand Up @@ -18,6 +18,10 @@
expect_no_offenses('a = self.a')
end

it 'accepts when nested receiver and lvalue have the name name' do
expect_no_offenses('a = self.a || b || c')
end

it 'does not report an offense when receiver and multiple assigned lvalue ' \
'have the same name' do
expect_no_offenses('a, b = self.a')
Expand Down