Skip to content

Commit

Permalink
Add to the offense message that URI.regexp is obsolete
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Sep 10, 2017
1 parent c5bf278 commit 00835fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions lib/rubocop/cop/lint/uri_regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module RuboCop
module Cop
module Lint
# This cop identifies places where `URI.regexp`
# can be replaced by `URI::DEFAULT_PARSER.make_regexp`.
# This cop identifies places where `URI.regexp` is obsolete and should
# not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp`.
#
# @example
# # bad
Expand All @@ -14,8 +14,9 @@ module Lint
# URI::DEFAULT_PARSER.make_regexp('http://example.com')
#
class UriRegexp < Cop
MSG = 'Use `%<top_level>sURI::DEFAULT_PARSER.make_regexp%<arg>s` ' \
'instead of `%<top_level>sURI.regexp%<arg>s`.'.freeze
MSG = '`%<top_level>sURI.regexp%<arg>s` is obsolete and should not ' \
'be used. Instead, use `%<top_level>sURI::DEFAULT_PARSER.' \
'make_regexp%<arg>s`.'.freeze

def_node_matcher :uri_regexp_with_argument?, <<-PATTERN
(send
Expand Down
4 changes: 2 additions & 2 deletions manual/cops_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -2043,8 +2043,8 @@ Enabled by default | Supports autocorrection
--- | ---
Enabled | Yes

This cop identifies places where `URI.regexp`
can be replaced by `URI::DEFAULT_PARSER.make_regexp`.
This cop identifies places where `URI.regexp` is obsolete and should
not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp`.

### Example

Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cop/lint/uri_regexp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
it 'registers an offense when using `URI.regexp` with argument' do
expect_offense(<<-RUBY.strip_indent)
URI.regexp('http://example.com')
^^^^^^ Use `URI::DEFAULT_PARSER.make_regexp('http://example.com')` instead of `URI.regexp('http://example.com')`.
^^^^^^ `URI.regexp('http://example.com')` is obsolete and should not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp('http://example.com')`.
RUBY
end

it 'registers an offense when using `::URI.regexp` with argument' do
expect_offense(<<-RUBY.strip_indent)
::URI.regexp('http://example.com')
^^^^^^ Use `::URI::DEFAULT_PARSER.make_regexp('http://example.com')` instead of `::URI.regexp('http://example.com')`.
^^^^^^ `::URI.regexp('http://example.com')` is obsolete and should not be used. Instead, use `::URI::DEFAULT_PARSER.make_regexp('http://example.com')`.
RUBY
end

it 'registers an offense when using `URI.regexp` without argument' do
expect_offense(<<-RUBY.strip_indent)
URI.regexp
^^^^^^ Use `URI::DEFAULT_PARSER.make_regexp` instead of `URI.regexp`.
^^^^^^ `URI.regexp` is obsolete and should not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp`.
RUBY
end

it 'registers an offense when using `::URI.regexp` without argument' do
expect_offense(<<-RUBY.strip_indent)
::URI.regexp
^^^^^^ Use `::URI::DEFAULT_PARSER.make_regexp` instead of `::URI.regexp`.
^^^^^^ `::URI.regexp` is obsolete and should not be used. Instead, use `::URI::DEFAULT_PARSER.make_regexp`.
RUBY
end

Expand Down

0 comments on commit 00835fb

Please sign in to comment.