Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalinavlakhe committed Aug 5, 2020
1 parent 29d162f commit b17f32a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 16 additions & 1 deletion docs/modules/ROOT/pages/cops_lint.adoc
Expand Up @@ -2368,8 +2368,23 @@ 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.

=== Examples

[source,ruby]
----
/(foo)bar/ =~ 'foobar'
# bad - always returns nil
puts $2 # => nil
# good
puts $1 # => foo
puts $1 # => foo
----

== Lint/ParenthesesAsGroupedExpression

Expand Down
9 changes: 6 additions & 3 deletions lib/rubocop/cop/lint/out_of_range_regexp_ref.rb
Expand Up @@ -5,14 +5,17 @@ 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.

#
# @example
#
# /(foo)bar/ =~ 'foobar'

#
# # bad - always returns nil
#
# puts $2 # => nil

#
# # good
#
# puts $1 # => foo
#
class OutOfRangeRegexpRef < Base
Expand Down

0 comments on commit b17f32a

Please sign in to comment.