Skip to content

Commit

Permalink
Remove rescue block and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalinavlakhe committed Aug 5, 2020
1 parent b17f32a commit b5e412a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 21 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/cops_lint.adoc
Expand Up @@ -2368,8 +2368,8 @@ p [''.frozen?, ''.encoding] #=> [true, #<Encoding:US-ASCII>]
| -
|===

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

Expand Down
13 changes: 3 additions & 10 deletions lib/rubocop/cop/lint/out_of_range_regexp_ref.rb
Expand Up @@ -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
#
Expand All @@ -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

Expand Down
8 changes: 0 additions & 8 deletions spec/rubocop/cop/lint/out_of_range_regexp_ref_spec.rb
Expand Up @@ -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, `/(?<foo>#{var}*)` is interpreted as `/(?<foo>*)`.
# So it does not offense when variables are used in regexp literals.
Expand Down

0 comments on commit b5e412a

Please sign in to comment.