Class: RuboCop::Cop::Performance::UriDefaultParser
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Performance::UriDefaultParser
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/performance/uri_default_parser.rb
Overview
Identifies places where ‘URI::Parser.new` can be replaced by `URI::DEFAULT_PARSER`.
Constant Summary collapse
- MSG =
'Use `%<double_colon>sURI::DEFAULT_PARSER` instead of `%<double_colon>sURI::Parser.new`.'
- RESTRICT_ON_SEND =
%i[new].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# 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 ? '::' : '' = format(MSG, double_colon: double_colon) add_offense(node, message: ) do |corrector| corrector.replace(node, "#{double_colon}URI::DEFAULT_PARSER") end end end |