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 pattern matching for Lint/OutOfRangeRegexpRef cop #11337

Merged

Conversation

fatkodima
Copy link
Contributor

Closes #10976.

Note: This is the first time I familiarized myself with the pattern matching in ruby, so be a little more careful when reviewing this PR.

@bbatsov bbatsov merged commit 2d0589a into rubocop:master Dec 31, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 31, 2022

Looks good to me.

@fatkodima fatkodima deleted the out_of_range_regexp_ref-pattern-matching branch December 31, 2022 16:00
pattern = pattern_node.node_parts[0]

case pattern.type
when :array_pattern, :match_alt
Copy link

Choose a reason for hiding this comment

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

@fatkodima @bbatsov
I may be wrong, as I only glanced at it, but I don't think it supports hash pattern/find pattern/value pattern with the pin operator(^(expression)).

{a: 'foo'} => {a: /(.)/}
p $1

['foo'] => [*, /(.)/, *]
p $1

'foo' => ^(/(.)/)
p $1

The last one may not need to be fixed since it is difficult to fully support and is not a practical code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reporting. Indeed, this PR's implementation should be done in a simpler way - #11573

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.

Lint/OutOfRangeRegexpRef does not detect captures from pattern matching syntax.
3 participants