Skip to content

Commit

Permalink
Merge pull request #8467 from koic/fix_false_positive_for_uri_regexp
Browse files Browse the repository at this point in the history
[Fix #8466] Fix a false positive for `Lint/UriRegexp`
  • Loading branch information
koic committed Aug 6, 2020
2 parents 3065500 + fadd404 commit 7acbdb8
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 7acbdb8

Please sign in to comment.