Skip to content

[#Fix 334] Make body consistent for RescueNode, EnsureNode and KeywordBeginNode#336

Draft
dvandersluis wants to merge 1 commit into
rubocop:masterfrom
dvandersluis:issue/334
Draft

[#Fix 334] Make body consistent for RescueNode, EnsureNode and KeywordBeginNode#336
dvandersluis wants to merge 1 commit into
rubocop:masterfrom
dvandersluis:issue/334

Conversation

@dvandersluis

@dvandersluis dvandersluis commented Nov 11, 2024

Copy link
Copy Markdown
Member

Renames EnsureNode#body to #branch, and adds a new #body method in line with RescueNode and KeywordBeginNode to return the body of code being executed before exception handling. For all three node types, body will now return a single node (which may be a begin/kwbegin node containing multiple nodes).

begin
  foo       <--- body
  bar       <--- body
rescue 
  baz
ensure
  quux
end

This is a breaking change, as existing code that calls EnsureNode#body will need to be updated.

Fixes #334.

@dvandersluis

Copy link
Copy Markdown
Member Author

I'm not sure when the plan for the next major version is, but getting this kicked off now so it's ready for whenever that'll be.

# Returns an the ensure branch in the exception handling statement.
#
# @return [Node, nil] the body of the ensure branch.
def branch

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used branch for the method to get the ensure branch body, similiar to how we have branches for RescueNode.

@dvandersluis

Copy link
Copy Markdown
Member Author

I've gone through every rubocop-* repo in the @rubocop org. As far as I can see, only rubocop/rubocop and rubocop/rubocop-minitest are affected by this change. For tracking purposes, here are the PRs to update EnsureNode.body in those repos:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistency between RescueNode and EnsureNode

1 participant