From b88f3ee9092c23548225bb8b122d18bb4b9b4846 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Sat, 17 Aug 2024 12:16:03 +0200 Subject: [PATCH] Mark `RuboCop::AST::EnsureNode` as being in a void context. --- changelog/change_mark_ensure_as_void_context.md | 1 + lib/rubocop/ast/node/ensure_node.rb | 8 ++++++++ spec/rubocop/ast/ensure_node_spec.rb | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 changelog/change_mark_ensure_as_void_context.md diff --git a/changelog/change_mark_ensure_as_void_context.md b/changelog/change_mark_ensure_as_void_context.md new file mode 100644 index 000000000..48feb65d8 --- /dev/null +++ b/changelog/change_mark_ensure_as_void_context.md @@ -0,0 +1 @@ +* [#309](https://github.com/rubocop/rubocop-ast/pull/309): Mark `RuboCop::AST::EnsureNode` as being in a void context. ([@earlopain][]) diff --git a/lib/rubocop/ast/node/ensure_node.rb b/lib/rubocop/ast/node/ensure_node.rb index a9be86449..769b8d343 100644 --- a/lib/rubocop/ast/node/ensure_node.rb +++ b/lib/rubocop/ast/node/ensure_node.rb @@ -12,6 +12,14 @@ class EnsureNode < Node def body node_parts[1] end + + # Checks whether this node body is a void context. + # Always `true` for `ensure`. + # + # @return [true] whether the `ensure` node body is a void context + def void_context? + true + end end end end diff --git a/spec/rubocop/ast/ensure_node_spec.rb b/spec/rubocop/ast/ensure_node_spec.rb index a2fe0ab21..2997340cd 100644 --- a/spec/rubocop/ast/ensure_node_spec.rb +++ b/spec/rubocop/ast/ensure_node_spec.rb @@ -14,4 +14,10 @@ it { expect(ensure_node.body).to be_sym_type } end + + describe '#void_context?' do + let(:source) { 'begin; beginbody; ensure; ensurebody; end' } + + it { expect(ensure_node).to be_void_context } + end end