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 #9588] Fix causing a variable to be shadowed from outside the rescue block #9961
[Fix #9588] Fix causing a variable to be shadowed from outside the rescue block #9961
Conversation
@@ -75,6 +75,9 @@ def on_resbody(node) | |||
preferred_name = preferred_name(offending_name) | |||
return if preferred_name.to_sym == offending_name | |||
|
|||
# check variable shadowing for exception variable | |||
return if check_shadowed_variable_name(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the caller name as well?
return if check_shadowed_variable_name(node) | |
return if shadowed_variable_name?(node) |
node.each_descendant(:lvar) do |n| | ||
return true if n.children.first.to_s == preferred_name(n) | ||
end | ||
false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that it can be simplified by using any?
.
def shadowed_variable_name?(node)
- node.each_descendant(:lvar) do |n|
- return true if n.children.first.to_s == preferred_name(n)
- end
- false
+ node.each_descendant(:lvar).any? { |n| n.children.first.to_s == preferred_name(n) }
end
@lilisako ping! |
@lilisako Can you make this CI successful? |
Looks like you need to rebase your branch. |
Sorry for getting back to you late. I'll do it within 5-6 hours! When it's done I'm doing to mention you. Thanks! |
…scue block This PR fixes causing a variable to be shadowed from outside the rescue block from Naming/RescuedExceptionsVariableName
@koic @dvandersluis |
Thanks! |
Fixes #9588
Fix causing a variable to be shadowed from outside the rescue block.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.