class RuboCop::Cop::Lint::UriRegexp
URI::RFC2396_PARSER.make_regexp(‘example.com’)
# good - Ruby 3.4 or higher
URI::DEFAULT_PARSER.make_regexp(‘example.com’)
# good - Ruby 3.3 or lower
URI.regexp(‘example.com’)
# bad
@example
—-
defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER
—-
[source,ruby]
consider manually changing the code as follows:
NOTE: If you need to support both Ruby 3.3 and lower as well as Ruby 3.4 and higher,
For Ruby 3.4 or higher, use ‘URI::RFC2396_PARSER.make_regexp`.
For Ruby 3.3 or lower, use `URI::DEFAULT_PARSER.make_regexp`.
Identifies places where `URI.regexp` is obsolete and should not be used.
def on_send(node)
def on_send(node) return unless uri_constant?(node.receiver) parser = target_ruby_version >= 3.4 ? 'RFC2396_PARSER' : 'DEFAULT_PARSER' argument = node.first_argument ? "(#{node.first_argument.source})" : '' preferred_method = "#{node.receiver.source}::#{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