123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Cop::Performance::UriDefaultParser

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, AutoCorrector, Base
Instance Chain:
self, Base
Inherits: Base
  • Object
Defined in: lib/rubocop/cop/performance/uri_default_parser.rb

Overview

Identifies places where URI::Parser.new can be replaced by URI::DEFAULT_PARSER.

Examples:

# bad
URI::Parser.new

# good
URI::DEFAULT_PARSER

Constant Summary

Instance Method Summary

Instance Method Details

#on_send(node)

[ GitHub ]

  
# File 'lib/rubocop/cop/performance/uri_default_parser.rb', line 27

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

    add_offense(node, message: message) do |corrector|
      corrector.replace(node, "#{double_colon}URI::DEFAULT_PARSER")
    end
  end
end