mirror of
https://github.com/lostisland/faraday.git
synced 2025-08-10 00:03:15 -04:00
chore: RuboCop indentations (#864)
* chore: RuboCop lint Layout/CaseIndentation * chore: RuboCop lint Layout/CommentIndentation * chore: RuboCop lint Layout/IndentationWidth * chore: RuboCop lint Layout/MultilineMethodCallIndentation * chore: RuboCop lint Layout/MultilineOperationIndentation
This commit is contained in:
parent
ec709b3974
commit
91ddced8b2
@ -26,21 +26,6 @@ Layout/BlockEndNewline:
|
||||
Exclude:
|
||||
- 'spec/faraday/request/multipart_spec.rb'
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
|
||||
# SupportedStyles: case, end
|
||||
Layout/CaseIndentation:
|
||||
Exclude:
|
||||
- 'lib/faraday/connection.rb'
|
||||
- 'test/helper.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Layout/CommentIndentation:
|
||||
Exclude:
|
||||
- 'lib/faraday/adapter/net_http.rb'
|
||||
|
||||
# Offense count: 7
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
@ -116,42 +101,12 @@ Layout/IndentHash:
|
||||
Exclude:
|
||||
- 'spec/support/streaming_response_checker.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Width, IgnoredPatterns.
|
||||
Layout/IndentationWidth:
|
||||
Exclude:
|
||||
- 'lib/faraday/adapter/rack.rb'
|
||||
- 'lib/faraday/connection.rb'
|
||||
- 'lib/faraday/options.rb'
|
||||
- 'lib/faraday/utils.rb'
|
||||
- 'test/live_server.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Layout/MultilineBlockLayout:
|
||||
Exclude:
|
||||
- 'spec/faraday/request/multipart_spec.rb'
|
||||
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
||||
# SupportedStyles: aligned, indented, indented_relative_to_receiver
|
||||
Layout/MultilineMethodCallIndentation:
|
||||
Exclude:
|
||||
- 'lib/faraday/connection.rb'
|
||||
- 'lib/faraday/utils/headers.rb'
|
||||
- 'spec/support/shared_examples/request_method.rb'
|
||||
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
||||
# SupportedStyles: aligned, indented
|
||||
Layout/MultilineOperationIndentation:
|
||||
Exclude:
|
||||
- 'lib/faraday/adapter/test.rb'
|
||||
- 'lib/faraday/utils.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Layout/RescueEnsureAlignment:
|
||||
|
@ -158,7 +158,7 @@ module Faraday
|
||||
end
|
||||
http.open_timeout = req[:open_timeout] if req[:open_timeout]
|
||||
http.write_timeout = req[:write_timeout] if req[:write_timeout] && http.respond_to?(:write_timeout=)
|
||||
# Only set if Net::Http supports it, since Ruby 2.5.
|
||||
# Only set if Net::Http supports it, since Ruby 2.5.
|
||||
http.max_retries = 0 if http.respond_to?(:max_retries=)
|
||||
|
||||
@config_block.call(http) if @config_block
|
||||
|
@ -41,7 +41,7 @@ module Faraday
|
||||
|
||||
timeout = env[:request][:timeout] || env[:request][:open_timeout]
|
||||
response = if timeout
|
||||
Timer.timeout(timeout, Faraday::TimeoutError) { execute_request(env, rack_env) }
|
||||
Timer.timeout(timeout, Faraday::TimeoutError) { execute_request(env, rack_env) }
|
||||
else
|
||||
execute_request(env, rack_env)
|
||||
end
|
||||
|
@ -148,10 +148,10 @@ module Faraday
|
||||
# that will be yielded to consumer block
|
||||
meta = {}
|
||||
return (host.nil? || host == request_host) &&
|
||||
path_match?(request_path, meta) &&
|
||||
params_match?(request_params) &&
|
||||
(body.to_s.size.zero? || request_body == body) &&
|
||||
headers_match?(request_headers), meta
|
||||
path_match?(request_path, meta) &&
|
||||
params_match?(request_params) &&
|
||||
(body.to_s.size.zero? || request_body == body) &&
|
||||
headers_match?(request_headers), meta
|
||||
end
|
||||
|
||||
def path_match?(request_path, meta)
|
||||
|
@ -398,7 +398,7 @@ module Faraday
|
||||
# @return [String] the new path prefix
|
||||
def path_prefix=(value)
|
||||
url_prefix.path = if value
|
||||
value = '/' + value unless value[0,1] == '/'
|
||||
value = '/' + value unless value[0,1] == '/'
|
||||
value
|
||||
end
|
||||
end
|
||||
@ -520,7 +520,7 @@ module Faraday
|
||||
|
||||
def set_authorization_header(header_type, *args)
|
||||
header = Faraday::Request.lookup_middleware(header_type).
|
||||
header(*args)
|
||||
header(*args)
|
||||
headers[Faraday::Request::Authorization::KEY] = header
|
||||
end
|
||||
|
||||
@ -531,12 +531,12 @@ module Faraday
|
||||
if URI.parse('').respond_to?(:find_proxy)
|
||||
case url
|
||||
when String
|
||||
uri = Utils.URI(url)
|
||||
uri = Utils.URI(url)
|
||||
uri = URI.parse("#{uri.scheme}://#{uri.hostname}").find_proxy
|
||||
when URI
|
||||
uri = url.find_proxy
|
||||
when nil
|
||||
uri = find_default_proxy
|
||||
when URI
|
||||
uri = url.find_proxy
|
||||
when nil
|
||||
uri = find_default_proxy
|
||||
end
|
||||
else
|
||||
warn 'no_proxy is unsupported' if ENV['no_proxy'] || ENV['NO_PROXY']
|
||||
|
@ -197,7 +197,7 @@ module Faraday
|
||||
|
||||
def self.fetch_error_class
|
||||
@fetch_error_class ||= if Object.const_defined?(:KeyError)
|
||||
::KeyError
|
||||
::KeyError
|
||||
else
|
||||
::IndexError
|
||||
end
|
||||
|
@ -68,7 +68,7 @@ module Faraday
|
||||
|
||||
def default_uri_parser=(parser)
|
||||
@default_uri_parser = if parser.respond_to?(:call) || parser.nil?
|
||||
parser
|
||||
parser
|
||||
else
|
||||
parser.method(:parse)
|
||||
end
|
||||
@ -78,7 +78,7 @@ module Faraday
|
||||
def normalize_path(url)
|
||||
url = URI(url)
|
||||
(url.path.start_with?('/') ? url.path : '/' + url.path) +
|
||||
(url.query ? "?#{sort_query_params(url.query)}" : "")
|
||||
(url.query ? "?#{sort_query_params(url.query)}" : "")
|
||||
end
|
||||
|
||||
# Recursive hash update
|
||||
|
@ -40,8 +40,8 @@ module Faraday
|
||||
key
|
||||
else
|
||||
key.to_s.split('_') # :user_agent => %w(user agent)
|
||||
.each { |w| w.capitalize! } # => %w(User Agent)
|
||||
.join('-') # => "User-Agent"
|
||||
.each { |w| w.capitalize! } # => %w(User Agent)
|
||||
.join('-') # => "User-Agent"
|
||||
end
|
||||
keymap_mutex.synchronize { map[key] = value }
|
||||
end
|
||||
|
@ -144,9 +144,9 @@ shared_examples 'a request method' do |http_method|
|
||||
payload1 = { a: '1' }
|
||||
payload2 = { b: '2' }
|
||||
request_stub.with(Hash[query_or_body, payload1])
|
||||
.to_return(body: payload1.to_json)
|
||||
.to_return(body: payload1.to_json)
|
||||
stub_request(http_method, remote).with(Hash[query_or_body, payload2])
|
||||
.to_return(body: payload2.to_json)
|
||||
.to_return(body: payload2.to_json)
|
||||
|
||||
conn.in_parallel do
|
||||
resp1 = conn.public_send(http_method, '/', payload1)
|
||||
|
@ -21,10 +21,10 @@ module Faraday
|
||||
module LiveServerConfig
|
||||
def live_server=(value)
|
||||
@@live_server = case value
|
||||
when /^http/
|
||||
URI(value)
|
||||
when /./
|
||||
URI('http://127.0.0.1:4567')
|
||||
when /^http/
|
||||
URI(value)
|
||||
when /./
|
||||
URI('http://127.0.0.1:4567')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,85 +2,85 @@ require 'sinatra/base'
|
||||
require_relative 'shared'
|
||||
|
||||
module Faraday
|
||||
class LiveServer < Sinatra::Base
|
||||
set :environment, :test
|
||||
disable :logging
|
||||
disable :protection
|
||||
|
||||
[:get, :post, :put, :patch, :delete, :options].each do |method|
|
||||
send(method, '/echo') do
|
||||
kind = request.request_method.downcase
|
||||
out = kind.dup
|
||||
out << ' ?' << request.GET.inspect if request.GET.any?
|
||||
out << ' ' << request.POST.inspect if request.POST.any?
|
||||
|
||||
content_type 'text/plain'
|
||||
return out
|
||||
end
|
||||
end
|
||||
|
||||
[:get, :post].each do |method|
|
||||
send(method, '/stream') do
|
||||
content_type :txt
|
||||
stream do |out|
|
||||
out << request.GET.inspect if request.GET.any?
|
||||
out << request.POST.inspect if request.POST.any?
|
||||
out << Faraday::Shared.big_string
|
||||
class LiveServer < Sinatra::Base
|
||||
set :environment, :test
|
||||
disable :logging
|
||||
disable :protection
|
||||
|
||||
[:get, :post, :put, :patch, :delete, :options].each do |method|
|
||||
send(method, '/echo') do
|
||||
kind = request.request_method.downcase
|
||||
out = kind.dup
|
||||
out << ' ?' << request.GET.inspect if request.GET.any?
|
||||
out << ' ' << request.POST.inspect if request.POST.any?
|
||||
|
||||
content_type 'text/plain'
|
||||
return out
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[:get, :post].each do |method|
|
||||
send(method, '/empty_stream') do
|
||||
content_type :txt
|
||||
stream do |out|
|
||||
out << ""
|
||||
|
||||
[:get, :post].each do |method|
|
||||
send(method, '/stream') do
|
||||
content_type :txt
|
||||
stream do |out|
|
||||
out << request.GET.inspect if request.GET.any?
|
||||
out << request.POST.inspect if request.POST.any?
|
||||
out << Faraday::Shared.big_string
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
get '/echo_header' do
|
||||
header = "HTTP_#{params[:name].tr('-', '_').upcase}"
|
||||
request.env.fetch(header) { 'NONE' }
|
||||
end
|
||||
|
||||
post '/file' do
|
||||
if params[:uploaded_file].respond_to? :each_key
|
||||
"file %s %s %d" % [
|
||||
params[:uploaded_file][:filename],
|
||||
params[:uploaded_file][:type],
|
||||
params[:uploaded_file][:tempfile].size
|
||||
]
|
||||
else
|
||||
status 400
|
||||
|
||||
[:get, :post].each do |method|
|
||||
send(method, '/empty_stream') do
|
||||
content_type :txt
|
||||
stream do |out|
|
||||
out << ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
get '/echo_header' do
|
||||
header = "HTTP_#{params[:name].tr('-', '_').upcase}"
|
||||
request.env.fetch(header) { 'NONE' }
|
||||
end
|
||||
|
||||
post '/file' do
|
||||
if params[:uploaded_file].respond_to? :each_key
|
||||
"file %s %s %d" % [
|
||||
params[:uploaded_file][:filename],
|
||||
params[:uploaded_file][:type],
|
||||
params[:uploaded_file][:tempfile].size
|
||||
]
|
||||
else
|
||||
status 400
|
||||
end
|
||||
end
|
||||
|
||||
get '/multi' do
|
||||
[200, { 'Set-Cookie' => 'one, two' }, '']
|
||||
end
|
||||
|
||||
get '/who-am-i' do
|
||||
request.env['REMOTE_ADDR']
|
||||
end
|
||||
|
||||
get '/slow' do
|
||||
sleep 10
|
||||
[200, {}, 'ok']
|
||||
end
|
||||
|
||||
get '/204' do
|
||||
status 204 # no content
|
||||
end
|
||||
|
||||
get '/ssl' do
|
||||
request.secure?.to_s
|
||||
end
|
||||
|
||||
error do |e|
|
||||
"#{e.class}\n#{e.to_s}\n#{e.backtrace.join("\n")}"
|
||||
end
|
||||
end
|
||||
|
||||
get '/multi' do
|
||||
[200, { 'Set-Cookie' => 'one, two' }, '']
|
||||
end
|
||||
|
||||
get '/who-am-i' do
|
||||
request.env['REMOTE_ADDR']
|
||||
end
|
||||
|
||||
get '/slow' do
|
||||
sleep 10
|
||||
[200, {}, 'ok']
|
||||
end
|
||||
|
||||
get '/204' do
|
||||
status 204 # no content
|
||||
end
|
||||
|
||||
get '/ssl' do
|
||||
request.secure?.to_s
|
||||
end
|
||||
|
||||
error do |e|
|
||||
"#{e.class}\n#{e.to_s}\n#{e.backtrace.join("\n")}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
|
Loading…
x
Reference in New Issue
Block a user