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

Use node groups in node patterns to replace unions of types #2025

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dvandersluis
Copy link
Member

rubocop-ast defines some node groups (https://github.com/rubocop/rubocop-ast/blob/85bfe84/lib/rubocop/ast/node.rb#L89-L116) that can be used in place of a union of node types.

rubocop-ast v1.38.0 is needed for any_block. I added it to the gemspec in this PR but if you'd prefer to handle it later, I can remove the any_block changes.

@dvandersluis dvandersluis requested a review from a team as a code owner January 27, 2025 20:53
@dvandersluis
Copy link
Member Author

CI failures are unrelated to this PR but due to rubocop/rubocop#13719.

@bquorning
Copy link
Collaborator

Yeah, I think v1.38.0 is a bit too recent for us to set as a hard requirement. Postponing the use of any_block, which version of rubocop-ast is then required?

@bquorning
Copy link
Collaborator

CI failures are unrelated to this PR but due to rubocop/rubocop#13719.

The CI failures are fixed in #2026.

@dvandersluis
Copy link
Member Author

dvandersluis commented Jan 27, 2025

@bquorning I updated the PR to skip {block numblock} => any_block for now. It appears that the version you use as "Oldest RuboCop" is 1.61, which shouldn't have a problem handling the other node group types.

Other than any_block, it looks like the latest group added was argument in 2020 (rubocop-ast 0.1.0).

@dvandersluis
Copy link
Member Author

The CI failures are fixed in #2026.

Thank you! I'll rebase once it's been merged.

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -45,7 +45,7 @@ class BeEql < Base

# @!method eql_type_with_identity(node)
def_node_matcher :eql_type_with_identity, <<~PATTERN
(send _ :to $(send nil? :eql {true false int float sym nil}))
(send _ :to $(send nil? :eql {boolean int float sym nil}))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(send _ :to $(send nil? :eql {boolean int float sym nil}))
(send _ :to $(send nil? :eql {boolean numeric sym nil}))

This needs to be checked though, and the doc above needs to be adjusted.

I don’t mind leaving this out

Copy link
Member Author

@dvandersluis dvandersluis Jan 28, 2025

Choose a reason for hiding this comment

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

numeric is more than int and float (also rational and complex), so up to you if you want to change behaviour. I was only making equivalent changes 😄

@pirj
Copy link
Member

pirj commented Jan 28, 2025

Oldest RuboCop" is 1.61

we can update that together with bumping the dependency in the gemspec.

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.

3 participants