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

Lint/MixedRegexpCaptureTypes fails for multiline regex with comments #8845

Closed
bkuhlmann opened this issue Oct 3, 2020 · 2 comments
Closed

Comments

@bkuhlmann
Copy link

Expected behavior

I would expect Rubocop to not flag multi-line regular expressions with comments as invalid.

Actual behavior

End up with the following error:

Lint/MixedRegexpCaptureTypes: Do not mix named captures and numbered captures in a Regexp literal.

Steps to reproduce the problem

You can recreate the issue as follows:

# frozen_string_literal: true

SUCCESS = /
  (?<key>\A.+)
/x.freeze

FAILURE = /
  (?<key>\A.+)  # Key (anchored to start of line).
/x.freeze

If you save the above to example.rb and run rubocop example.rb, you'll get the following error:

Inspecting 1 file
W

Offenses:

example.rb:3:19: W: Lint/MixedRegexpCaptureTypes: Do not mix named captures and numbered captures in a Regexp literal.
PATTERN_FAILURE = / ...
                  ^

1 file inspected, 1 offense detected, 1 offense auto-correctable

RuboCop version

0.92.0 (using Parser 2.7.1.5, rubocop-ast 0.7.1, running on ruby 2.7.2 x86_64-darwin19)
bkuhlmann added a commit to bkuhlmann/git-lint that referenced this issue Oct 3, 2020
This is a false positive with Rubocop where comments with a multi-line
regular expression cause Rubocop to flag this as a violation. I've
logged an [issue](rubocop/rubocop#8845) to
address this.
@dvandersluis
Copy link
Member

I think this was fixed by #8803 already!

@koic koic closed this as completed Oct 3, 2020
@bkuhlmann
Copy link
Author

🙇 @dvandersluis Perfect. I was searching for open/closed issues related to Lint/MixedRegexpCaptureType but didn't see that at all. I look forward to the next release.

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

No branches or pull requests

3 participants