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
Add "No mix named and numbered captures" rule #793
Add "No mix named and numbered captures" rule #793
Conversation
f63356e
to
b04abc7
Compare
README.adoc
Outdated
@@ -4336,6 +4336,26 @@ Use non-capturing groups when you don't use the captured result. | |||
/(?:first|second)/ | |||
---- | |||
|
|||
=== No mix named and numbered captures [[no-mix-named-and-numbered-captures]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Do not mix...
is better wording here. Same for the anchor.
=== No mix named and numbered captures [[no-mix-named-and-numbered-captures]] | ||
|
||
Do not mix named captures and numbered captures in a Regexp literal. | ||
Because numbered capture is ignored if they're mixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a good idea to illustrate what does this mean in practice.
README.adoc
Outdated
# good | ||
/(?<foo>FOO)(?<bar>BAR)/ | ||
|
||
# good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add some comments explaining examples like this one, as I'm pretty sure many people are not familiar with non-capturing groups.
Thanks! Great work! 🙇 |
- This rule is rubocop/ruby-style-guide#793 - Perhaps we can investigate what can be done with this regular expression, to not need those extra capture groups?
- This rule is rubocop/ruby-style-guide#793 - Perhaps we can investigate what can be done with this regular expression, to not need those extra capture groups?
- This rule is rubocop/ruby-style-guide#793 - Perhaps we can investigate what can be done with this regular expression, to not need those extra capture groups?
I created Lint/MixedRegexpCaptureTypes cop in rubocop/rubocop#7749.
This pull request adds a mention of the problem to the style guide also.