Skip to content

Commit

Permalink
Fix false positive in Style/RedundantSelf cop with nested self ac…
Browse files Browse the repository at this point in the history
…cess (#8585)
  • Loading branch information
marcotc committed Oct 21, 2020
1 parent b4873b7 commit 89c9628
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -203,6 +203,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 @@ -129,6 +129,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

0 comments on commit 89c9628

Please sign in to comment.