diff --git a/CHANGELOG.md b/CHANGELOG.md index b18d71945..bc48f559d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### New features + +* [#122](https://github.com/rubocop-hq/rubocop-ast/pull/122): Add `Node#parent?` and `Node#root?`. ([@marcandre][]) + ### Changes * [#121](https://github.com/rubocop-hq/rubocop-ast/pull/121): Update from `Parser::Ruby28` to `Parser::Ruby30` for Ruby 3.0 parser (experimental). ([@koic][]) diff --git a/lib/rubocop/ast/node.rb b/lib/rubocop/ast/node.rb index 3ab160625..49ab65475 100644 --- a/lib/rubocop/ast/node.rb +++ b/lib/rubocop/ast/node.rb @@ -92,6 +92,16 @@ def parent=(node) @mutable_attributes[:parent] = node end + # @return [Boolean] + def parent? + !!parent + end + + # @return [Boolean] + def root? + !parent + end + def complete! @mutable_attributes.freeze each_child_node(&:complete!)