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

Make Node#class_constructor? aware of Data.define and numbered parameters #255

Merged

Conversation

koic
Copy link
Member

@koic koic commented Feb 7, 2023

This PR contains the following two commits:

Make Node#class_construcor? aware of Ruby 3.2's Data.define

Ruby 3.2 introduced immutable Data.define. Since this is similar to Struct.new, Node#class_constructor will handle it in the same way.

Make Node#class_constructor? aware of Ruby 2.7's numbered parameters

Class.new, Module.new, Struct.new, and Data.define take themselves as a block parameter.
These are the same when using numbered block parameter.

I will try to update rubocop/rubocop#11546 and rubocop/rubocop#11547 with this feature.

Ruby 3.2 introduced immutable `Data.define`. Since this is similar to `Struct.new`,
`Node#class_constructor` will handle it in the same way.
`Class.new`, `Module.new`, `Struct.new`, and `Data.define` take themselves as a block parameter.
These are the same when using numbered block parameter.
@koic koic changed the title Make Node#class_constructor aware of Data.define and numbered parameters Make Node#class_constructor? aware of Data.define and numbered parameters Feb 7, 2023
Copy link
Contributor

@Drenmi Drenmi left a comment

Choose a reason for hiding this comment

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

🚀

{
(send #global_const?({:Class :Module :Struct}) :new ...)
(send #global_const?(:Data) :define ...)
({block numblock} {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good, but makes me wonder if we shouldn't have a pseudo type to include both of these... Maybe any_block or a_block instead of {block numblock}

@marcandre marcandre merged commit 954781a into rubocop:master Feb 11, 2023
@marcandre
Copy link
Contributor

Thanks! 🚀

@marcandre
Copy link
Contributor

Released as 1.26

@koic koic deleted the make_class_constructor_aware_of_data_class branch February 11, 2023 16:58
koic added a commit to rubocop/rubocop that referenced this pull request Feb 11, 2023
Follow up rubocop/rubocop-ast#255.

`RuboCop::AST::Node#class_constructor?` has been introduced in RuboCop AST 1.26.0.
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