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

NodePattern: Use param === node to match params. #31

Merged
merged 1 commit into from
Jun 11, 2020

Conversation

marcandre
Copy link
Contributor

Used to be node == param.

For most classes, === is the same as ==, and == is symmetric, so this has no impact, except for Regexp, Class, Proc, Set, Range, none of which can exist in the AST.

This opens many cool patterns though:

  • (hash <(pair (_ %1) $_)>...) called with a regexp to match a symbol/string key

  • (send _ %1 ...) called with Set of possible method names to match.

etc.

Thanks to @pirj for bringing this to my attention

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.

Awesome, thank you so much!

@@ -374,6 +374,41 @@ def_node_matcher :initializing_with_user?, <<~PATTERN
PATTERN
----

== `%` for arguments
Copy link
Member

Choose a reason for hiding this comment

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

👍 I was looking for this section today.

pirj added a commit to rubocop/rubocop-rspec that referenced this pull request Jun 11, 2020
#804 (comment)
Support introduced in rubocop/rubocop-ast#31
Presumably this will land in RuboCop 1.0 or 1.0.1 worst case.
@pirj
Copy link
Member

pirj commented Jun 11, 2020

Works as expected 👍 https://github.com/rubocop-hq/rubocop-rspec/pull/930/files#diff-2aecb8a103588de3553f5448956d701fR87

@marcandre marcandre merged commit 1899234 into rubocop:master Jun 11, 2020
@marcandre marcandre deleted the nodepatternmatch branch June 11, 2020 20:49
@marcandre
Copy link
Contributor Author

I'll check about accepting %MY_CONSTANT too, should make things like this both nicer and more efficient I think.

pirj added a commit to rubocop/rubocop-rspec that referenced this pull request Jul 15, 2020
#804 (comment)
Support introduced in rubocop/rubocop-ast#31
Presumably this will land in RuboCop 1.0 or 1.0.1 worst case.
pirj added a commit to rubocop/rubocop-rspec that referenced this pull request Jul 15, 2020
#804 (comment)
Support introduced in rubocop/rubocop-ast#31
Presumably this will land in RuboCop 1.0 or 1.0.1 worst case.
pirj added a commit to rubocop/rubocop-rspec that referenced this pull request Jul 15, 2020
#804 (comment)
Support introduced in rubocop/rubocop-ast#31
Presumably this will land in RuboCop 1.0 or 1.0.1 worst case.
pirj added a commit to rubocop/rubocop-rspec that referenced this pull request Jul 15, 2020
#804 (comment)
Support introduced in rubocop/rubocop-ast#31
Presumably this will land in RuboCop 1.0 or 1.0.1 worst case.
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.

2 participants