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

Introduce RuboCop::Ast::MethodDispatchNode#selector #267

Merged

Conversation

gsamokovarov
Copy link
Contributor

@gsamokovarov gsamokovarov commented May 30, 2023

If you need to manipulate the call-site of a method dispatch, you have to use node.loc.selector for regular methods and node.loc.keyword for syntax nodes that behave like method invocations. Super and yield nodes are nodes are examples.

This forces us to check if node.loc responds to #keyword in a few places in rubocop proper and we can make it easier if we expose a single method called #selector (the name is up for debate) and use it for method dispatch nodes.

As an example, see HashSyntaxShorthand where I had to define a struct to hide away the selector detection.

@marcandre
Copy link
Contributor

Thanks for the PR @gsamokovarov .

No problem for rubocop-ast, but for contributions for rubocop, please check the preferred way to make entries.

I think this is a good idea, but would I would like to know what @koic thinks about it

.rubocop.yml Outdated Show resolved Hide resolved
@bbatsov
Copy link
Contributor

bbatsov commented May 31, 2023

For the record - it looks like a reasonable addition to me. Frankly, I don't see much point in parser treating those differently.

If you need to manipulate the call-site of a method dispatch, you have
to use node.loc.selector for regular methods and node.loc.keyword for
syntax nodes that behave like method invocations, but are not. Super and
yield nodes are an example of that.

This forces us to check if node.loc responds to #keyword in a few places
in rubocop proper and we can make it easier if we expose a method, here
I have called it #selector, to all method dispatch nodes and work with
it.
@marcandre marcandre merged commit 53c69cd into rubocop:master Jun 1, 2023
18 of 19 checks passed
@marcandre
Copy link
Contributor

Thanks @bbatsov and @gsamokovarov

Released as v1.29.0 👍

@gsamokovarov
Copy link
Contributor Author

Thank you! ❤️

@gsamokovarov gsamokovarov deleted the selector-for-yield-and-super branch June 2, 2023 09:18
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