Skip to content

Commit

Permalink
[Fix rubocop#8466] Fix a false positive for Lint/UriRegexp
Browse files Browse the repository at this point in the history
Fixes rubocop#8466.

This PR fixes a false positive for `Lint/UriRegexp`
when using `regexp` method without receiver.
  • Loading branch information
koic committed Aug 6, 2020
1 parent d0bee92 commit fadd404
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
### Bug fixes

* [#8463](https://github.com/rubocop-hq/rubocop/pull/8463): Fix false positives for `Lint/OutOfRangeRegexpRef` when a regexp is defined and matched in separate steps. ([@eugeneius][])
* [#8466](https://github.com/rubocop-hq/rubocop/issues/8466): Fix a false positive for `Lint/UriRegexp` when using `regexp` method without receiver. ([@koic][])

## 0.89.0 (2020-08-05)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/uri_regexp.rb
Expand Up @@ -32,7 +32,7 @@ class UriRegexp < Base
PATTERN

def on_send(node)
return unless node.method?(:regexp)
return unless node.method?(:regexp) && node.receiver

captured_values = uri_regexp_with_argument?(node) || uri_regexp_without_argument?(node)

Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/lint/uri_regexp_spec.rb
Expand Up @@ -5,6 +5,12 @@

let(:config) { RuboCop::Config.new }

it 'does not register an offense when using `regexp` without receiver' do
expect_no_offenses(<<~RUBY)
regexp('http://example.com')
RUBY
end

it 'registers an offense and corrects using `URI.regexp` with argument' do
expect_offense(<<~RUBY)
URI.regexp('http://example.com')
Expand Down

0 comments on commit fadd404

Please sign in to comment.