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 and "premature end of pattern" #8083
Comments
We are facing a similar issue. I've created a SSCCE as well. # rubocop_regexp.rb
'Hello'.gsub(/]\[/, "_") $ rubocop --only Lint/MixedRegexpCaptureTypes rubocop_regexp.rb
Inspecting 1 file
An error occurred while Lint/MixedRegexpCaptureTypes cop was inspecting /private/tmp/rubocop_regexp.rb:1:13.
To see the complete backtrace run rubocop -d.
.
1 file inspected, no offenses detected
1 error occurred:
An error occurred while Lint/MixedRegexpCaptureTypes cop was inspecting /private/tmp/rubocop_regexp.rb:1:13.
Errors are usually caused by RuboCop bugs. Relevant part of the stacktrace:
And here a working example in Rubular. The fix for us would be to write |
I guess this can be some other cop, as that's an orthogonal concern issues in any specific cop. For the cops - I think it'd be best to just ignore regular expressions that raise such an error in the cops. |
Another example that is raising this error for us in case it is needed: Regex:
|
I hope the gem can be modified. JS (and I suspect many other languages) parse regexp this way and it doesn't seem such a quirk to me. |
I believe this error (exception) is related:
This is the line it's scanning: body.gsub(/( ?){{ ?first_name( ?\| ?default: '.+')? ?}}/) do I'm using version:
This might be helpful:
Output
|
I created ammar/regexp_parser#63 for regexp_parser. If nobody will act on it till weekend, I'll try looking at it myself. |
hit the same issue:
|
Fixes rubocop#8083. This PR fixes an error for `Lint/MixedRegexpCaptureTypes` cop when using a regular expression that cannot be processed by regexp_parser gem. https://github.com/ammar/regexp_parser Probably false negatives will be made, however false negatives will be reduced when a processing pattern of regexp_parser increases. So this PR relies on regexp_parser for error resolution.
Same issue on a regexp that looks like this:
|
Fixes #8083. This PR fixes an error for `Lint/MixedRegexpCaptureTypes` cop when using a regular expression that cannot be processed by regexp_parser gem. https://github.com/ammar/regexp_parser Probably false negatives will be made, however false negatives will be reduced when a processing pattern of regexp_parser increases. So this PR relies on regexp_parser for error resolution.
New cops, relying on Regexp parser might fell on something that is valid Ruby regexp. My example:
Here we are doing a pretty nasty thing (in specs): scanning HTML-with-JS rendered view, find one JSON object there (and then parse and check this object). But this is still valid Ruby, and it "just works".
When
Lint/MixedRegexpCaptureTypes
tries to scan it, it falls with the "Premature end of pattern" exception in the scanner.The deal is, formally, in Ruby regexps
{}
is for quantifiers (for ex.,x{15}
), but if it is not a valid quantifier:{}
as just textregexp-parser is kinda "theoretically right", but it leads to what is perceived as a "bug" by Rubocop users. It seems like one of the solutions below might be reasonable:
The text was updated successfully, but these errors were encountered: