Skip to content

Commit

Permalink
Mark RuboCop::AST::EnsureNode as being in a void context.
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Aug 17, 2024
1 parent b463c7d commit b88f3ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/change_mark_ensure_as_void_context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#309](https://github.com/rubocop/rubocop-ast/pull/309): Mark `RuboCop::AST::EnsureNode` as being in a void context. ([@earlopain][])
8 changes: 8 additions & 0 deletions lib/rubocop/ast/node/ensure_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions spec/rubocop/ast/ensure_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b88f3ee

Please sign in to comment.