diff --git a/CHANGELOG.md b/CHANGELOG.md index e15f25a35e2..399e16c7f38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## 0.85.0 (2020-06-01) +### Bug fixes + +* [#8083](https://github.com/rubocop-hq/rubocop/issues/8083): Fix an error for `Lint/MixedRegexpCaptureTypes` cop when using a regular expression that cannot be processed by regexp_parser gem. ([@koic][]) + ### New features * [#6289](https://github.com/rubocop-hq/rubocop/issues/6289): Add new `CheckDefinitionPathHierarchy` option for `Naming/FileName`. ([@jschneid][]) diff --git a/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb b/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb index 68dfcfe7853..ad3d9bb097b 100644 --- a/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +++ b/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb @@ -27,7 +27,14 @@ class MixedRegexpCaptureTypes < Cop def on_regexp(node) return if contain_non_literal?(node) - tree = Regexp::Parser.parse(node.content) + begin + tree = Regexp::Parser.parse(node.content) + # Returns if a regular expression that cannot be processed by regexp_parser gem. + # https://github.com/rubocop-hq/rubocop/issues/8083 + rescue Regexp::Scanner::ScannerError + return + end + return unless named_capture?(tree) return unless numbered_capture?(tree) diff --git a/spec/rubocop/cop/lint/mixed_regexp_capture_types_spec.rb b/spec/rubocop/cop/lint/mixed_regexp_capture_types_spec.rb index 0a9b7f21eee..49764887935 100644 --- a/spec/rubocop/cop/lint/mixed_regexp_capture_types_spec.rb +++ b/spec/rubocop/cop/lint/mixed_regexp_capture_types_spec.rb @@ -31,6 +31,13 @@ RUBY end + # See https://github.com/rubocop-hq/rubocop/issues/8083 + it 'does not register offense when using a Regexp cannot be processed by regexp_parser gem' do + expect_no_offenses(<<~'RUBY') + /data = ({"words":.+}}}[^}]*})/m + RUBY + end + # RuboCop does not know a value of variables that it will contain in the regexp literal. # For example, `/(?#{var}*)` is interpreted as `/(?*)`. # So it does not offense when variables are used in regexp literals.