Skip to content

Commit

Permalink
[Fix rubocop#10552] Fix a false positive for Lint/OutOfRangeRegexpRef
Browse files Browse the repository at this point in the history
Follow up rubocop/rubocop-ast#230 and fixes rubocop#10552.

This commit fixes a false positive for `Lint/OutOfRangeRegexpRef` when using
fixed-encoding regopt.
  • Loading branch information
koic authored and WJWH committed Aug 8, 2022
1 parent 73731fb commit 8788bee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
@@ -0,0 +1 @@
* [#10552](https://github.com/rubocop/rubocop/issues/10552): Require RuboCop AST 1.20.0+ to fix a false positive for `Lint/OutOfRangeRegexpRef` when using fixed-encoding regopt. ([@koic][])
2 changes: 1 addition & 1 deletion rubocop.gemspec
Expand Up @@ -37,7 +37,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('rainbow', '>= 2.2.2', '< 4.0')
s.add_runtime_dependency('regexp_parser', '>= 1.8', '< 3.0')
s.add_runtime_dependency('rexml', '>= 3.2.5', '< 4.0')
s.add_runtime_dependency('rubocop-ast', '>= 1.19.1', '< 2.0')
s.add_runtime_dependency('rubocop-ast', '>= 1.20.0', '< 2.0')
s.add_runtime_dependency('ruby-progressbar', '~> 1.7')
s.add_runtime_dependency('unicode-display_width', '>= 1.4.0', '< 3.0')

Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/lint/out_of_range_regexp_ref_spec.rb
Expand Up @@ -63,6 +63,14 @@
RUBY
end

it 'does not register offense to a regexp with encoding option and valid references for numbered captures' do
expect_no_offenses(<<~RUBY)
/(foo)(bar)/u =~ "foobar"
puts $1
puts $2
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 8788bee

Please sign in to comment.