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

Mark RuboCop::AST::EnsureNode as being in a void context. #309

Merged
merged 1 commit into from
Aug 17, 2024

Conversation

Earlopain
Copy link
Contributor

ensure nodes are somewhat special in that their last expression will not get implicitly returned.

def foo(do_rescue:)
  puts "begin called"
  raise if do_rescue
  "begin"
rescue
  puts "rescue called"
  "rescue"
ensure
  puts "ensure called"
  "ensure"
end

puts foo(do_rescue: false)
puts "----"
puts foo(do_rescue: true)

# =>
# begin called
# ensure called
# begin
# ----
# begin called
# rescue called
# ensure called
# rescue

This change will make it possible to properly teach Lint/Void about it.

@marcandre marcandre merged commit 0992ab1 into rubocop:master Aug 17, 2024
19 checks passed
@marcandre
Copy link
Contributor

Good catch, thanks!

@marcandre
Copy link
Contributor

Released as 1.32.1

@Earlopain Earlopain deleted the ensure-void-context branch August 17, 2024 16:44
@Earlopain
Copy link
Contributor Author

Thank you!

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.

2 participants