From b5e412af659e53eeda8f546a6d23c167edbdc176 Mon Sep 17 00:00:00 2001 From: Sonali Bhavsar Date: Wed, 5 Aug 2020 20:37:57 +0530 Subject: [PATCH] Remove rescue block and update test --- CHANGELOG.md | 1 - docs/modules/ROOT/pages/cops_lint.adoc | 4 ++-- lib/rubocop/cop/lint/out_of_range_regexp_ref.rb | 13 +++---------- .../cop/lint/out_of_range_regexp_ref_spec.rb | 8 -------- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cb6775e397..8896c4390c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,6 @@ * [#8417](https://github.com/rubocop-hq/rubocop/pull/8417): Add new `Style/GlobalStdStream` cop. ([@fatkodima][]) * [#7949](https://github.com/rubocop-hq/rubocop/issues/7949): Add new `Style/SingleArgumentDig` cop. ([@volfgox][]) * [#8341](https://github.com/rubocop-hq/rubocop/pull/8341): Add new `Lint/EmptyConditionalBody` cop. ([@fatkodima][]) -* [#7755](https://github.com/rubocop-hq/rubocop/issues/7755): Add new `Lint/OutOfRangeRefInRegexp` cop. ([@sonalinavlakhe][]) * [#7755](https://github.com/rubocop-hq/rubocop/issues/7755): Add new `Lint/OutOfRangeRegexpRef` cop. ([@sonalinavlakhe][]) ### Bug fixes diff --git a/docs/modules/ROOT/pages/cops_lint.adoc b/docs/modules/ROOT/pages/cops_lint.adoc index f40c2fc2627..aad7d1e956d 100644 --- a/docs/modules/ROOT/pages/cops_lint.adoc +++ b/docs/modules/ROOT/pages/cops_lint.adoc @@ -2368,8 +2368,8 @@ p [''.frozen?, ''.encoding] #=> [true, #] | - |=== -This cops looks for out of range referencing for Regexp, as while capturing groups out of -out of range reference always returns nil. +This cops looks for references of Regexp captures that are out of range +and thus always returns nil. === Examples diff --git a/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb b/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb index 0ca5e562abb..8a81e2a2f9b 100644 --- a/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +++ b/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb @@ -3,8 +3,8 @@ module RuboCop module Cop module Lint - # This cops looks for out of range referencing for Regexp, as while capturing groups out of - # out of range reference always returns nil. + # This cops looks for references of Regexp captures that are out of range + # and thus always returns nil. # # @example # @@ -29,14 +29,7 @@ def on_regexp(node) @valid_ref = nil return if contain_non_literal?(node) - 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 - + tree = Regexp::Parser.parse(node.content) @valid_ref = regexp_captures(tree) end diff --git a/spec/rubocop/cop/lint/out_of_range_regexp_ref_spec.rb b/spec/rubocop/cop/lint/out_of_range_regexp_ref_spec.rb index 50a2ff73e74..c386b08b8c0 100644 --- a/spec/rubocop/cop/lint/out_of_range_regexp_ref_spec.rb +++ b/spec/rubocop/cop/lint/out_of_range_regexp_ref_spec.rb @@ -67,14 +67,6 @@ 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 - puts $1 - 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.