Class: RuboCop::Cop::Legion::Framework::FaradayXmlMiddleware

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/legion/framework/faraday_xml_middleware.rb

Overview

Detects use of the removed ‘:xml` middleware in Faraday connection builders. Faraday >= 2.0 removed the built-in XML middleware.

Examples:

# bad
conn = Faraday.new do |f|
  f.request :xml
  f.response :xml
end

# good
conn = Faraday.new do |f|
  f.request :json
  f.response :json
end

Constant Summary collapse

MSG =
'Faraday >= 2.0 removed built-in `:xml` middleware. Do not add it to the connection builder.'
SEVERITY =
:error
RESTRICT_ON_SEND =
%i[request response].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



27
28
29
30
31
32
# File 'lib/rubocop/cop/legion/framework/faraday_xml_middleware.rb', line 27

def on_send(node)
  return unless node.first_argument&.sym_type?
  return unless node.first_argument.value == :xml

  add_offense(node, severity: SEVERITY)
end