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

Support node groups in Node#each_descendant and similar traversal methods #357

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

Earlopain
Copy link
Contributor

Sometimes it would be nice to do each_child_node(:call) instead of each_child_node(:send, :csend). This nicely mirrors that you can already use these aliases when writing node patterns

@@ -98,7 +95,7 @@ class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
kwrestarg: :argument,
blockarg: :argument,
forward_arg: :argument,
shardowarg: :argument,
shadowarg: :argument,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typo since this was added, tests caught it when I started using each_descendant(:argument)

@@ -528,6 +525,14 @@ def range_type?
GROUP_FOR_TYPE[type] == :range
end

def type_or_group_type?(type)
type == self.type || GROUP_FOR_TYPE[self.type] == type
end
Copy link
Member

Choose a reason for hiding this comment

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

I'm uncertain whether the behavior indicated by the name type_or_group_type? is clear. Since it currently seems to be called only from yield_for_types, how about not publishing type_or_group_type? and making it a private method instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took another look and seems like I just reimplemented the existing type? method. So, I removed both of these new methods instead.

Verified

This commit was signed with the committer’s verified signature.
drazisil-codecov Joe Becher
…ethods

Sometimes it would be nice to do `each_child_node(:call)` instead of `each_child_node(:send, :csend)`.
This nicely mirrors that you can already use these aliases when writing node patterns
@Earlopain Earlopain force-pushed the visit-X-group-types branch from 871144b to d6908ad Compare January 22, 2025 09:11
@marcandre marcandre merged commit 757c3cc into rubocop:master Jan 22, 2025
21 checks passed
@marcandre
Copy link
Contributor

Totally! ❤️
Thanks

Earlopain added a commit to Earlopain/rubocop that referenced this pull request Jan 28, 2025
Earlopain added a commit to Earlopain/rubocop that referenced this pull request Jan 28, 2025
Earlopain added a commit to Earlopain/rubocop that referenced this pull request Jan 28, 2025
Earlopain added a commit to Earlopain/rubocop that referenced this pull request Jan 28, 2025
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.

None yet

3 participants