class RuboCop::Cop::Lint::UriRegexp
Identifies places where `URI.regexp` is obsolete and should not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp`.
@example
# bad URI.regexp('http://example.com') # good URI::DEFAULT_PARSER.make_regexp('http://example.com')
Constants
- MSG
- RESTRICT_ON_SEND
- URI_CONSTANTS
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/lint/uri_regexp.rb, line 23 def on_send(node) return unless node.receiver return unless URI_CONSTANTS.include?(node.receiver.source) argument = node.first_argument ? "(#{node.first_argument.source})" : '' preferred_method = "#{node.receiver.source}::DEFAULT_PARSER.make_regexp#{argument}" message = format(MSG, current: node.source, preferred: preferred_method) add_offense(node.loc.selector, message: message) do |corrector| corrector.replace(node, preferred_method) end end