Skip to content

Commit

Permalink
[Fix #12236] Fix an error for Lint/ShadowedArgument
Browse files Browse the repository at this point in the history
Fixes #12236.

This PR fixes an error for `Lint/ShadowedArgument`
when self assigning to a block argument in `for`.
  • Loading branch information
koic authored and bbatsov committed Dec 31, 2023
1 parent 5457ca8 commit 01928d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_lint_shadowed_argument.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12236](https://github.com/rubocop/rubocop/issues/12236): Fix an error for `Lint/ShadowedArgument` when self assigning to a block argument in `for`. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/lint/shadowed_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def assignment_without_argument_usage(argument)

# Shorthand assignments always use their arguments
next false if assignment_node.shorthand_asgn?
next false unless assignment_node.parent

node_within_block_or_conditional =
node_within_block_or_conditional?(assignment_node.parent, argument.scope.node)
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/lint/shadowed_argument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ def do_something(*items)
end
end

context 'when self assigning to a block argument in `for`' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
for item in items
do_something { |arg| arg = arg }
end
RUBY
end
end

context 'when binding is used' do
it 'registers an offense' do
expect_offense(<<~RUBY)
Expand Down

0 comments on commit 01928d5

Please sign in to comment.