Sha256: 1dbdbfe091e0cafd8431503b4771b640652ca5cc2c328f10cbbbecdcb65f636a

Contents?: true

Size: 1.2 KB

Versions: 6794

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Performance
      # This cop identifies places where `URI::Parser.new`
      # can be replaced by `URI::DEFAULT_PARSER`.
      #
      # @example
      #   # bad
      #   URI::Parser.new
      #
      #   # good
      #   URI::DEFAULT_PARSER
      #
      class UriDefaultParser < Cop
        MSG = 'Use `%<double_colon>sURI::DEFAULT_PARSER` instead of ' \
              '`%<double_colon>sURI::Parser.new`.'.freeze

        def_node_matcher :uri_parser_new?, <<-PATTERN
          (send
            (const
              (const ${nil? cbase} :URI) :Parser) :new)
        PATTERN

        def on_send(node)
          return unless uri_parser_new?(node) do |captured_value|
            double_colon = captured_value ? '::' : ''
            message = format(MSG, double_colon: double_colon)

            add_offense(node, message: message)
          end
        end

        def autocorrect(node)
          lambda do |corrector|
            double_colon = uri_parser_new?(node) ? '::' : ''

            corrector.replace(
              node.loc.expression, "#{double_colon}URI::DEFAULT_PARSER"
            )
          end
        end
      end
    end
  end
end

Version data entries

6,794 entries across 6,788 versions & 26 rubygems

Version Path
primary_connect_proto-0.2.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
primary_connect_proto-0.1.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
primary_connect_proto-0.0.6 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-keto-client-0.7.0.alpha1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/performance/uri_default_parser.rb