mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-17 00:05:28 -04:00
Merge pull request #898 from lostisland/rubocop/styles
chore: RuboCop Style lints
This commit is contained in:
commit
3396561021
@ -1,6 +1,6 @@
|
|||||||
# This configuration was generated by
|
# This configuration was generated by
|
||||||
# `rubocop --auto-gen-config`
|
# `rubocop --auto-gen-config`
|
||||||
# on 2019-02-27 21:48:38 +0100 using RuboCop version 0.65.0.
|
# on 2019-02-28 17:29:46 +0000 using RuboCop version 0.65.0.
|
||||||
# The point is for the user to remove these configuration records
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
# Note that changes in the inspected code, or installation of new
|
# Note that changes in the inspected code, or installation of new
|
||||||
@ -572,61 +572,7 @@ Style/StructInheritance:
|
|||||||
- 'lib/faraday/request.rb'
|
- 'lib/faraday/request.rb'
|
||||||
- 'spec/faraday/rack_builder_spec.rb'
|
- 'spec/faraday/rack_builder_spec.rb'
|
||||||
|
|
||||||
# Offense count: 6
|
# Offense count: 271
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: MinSize.
|
|
||||||
# SupportedStyles: percent, brackets
|
|
||||||
Style/SymbolArray:
|
|
||||||
EnforcedStyle: brackets
|
|
||||||
|
|
||||||
# Offense count: 7
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: IgnoredMethods.
|
|
||||||
# IgnoredMethods: respond_to, define_method
|
|
||||||
Style/SymbolProc:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/faraday/options.rb'
|
|
||||||
- 'lib/faraday/upload_io.rb'
|
|
||||||
- 'lib/faraday/utils/headers.rb'
|
|
||||||
- 'spec/support/helper_methods.rb'
|
|
||||||
- 'test/shared.rb'
|
|
||||||
|
|
||||||
# Offense count: 3
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
|
|
||||||
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
|
|
||||||
Style/TernaryParentheses:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/faraday/adapter/test.rb'
|
|
||||||
- 'lib/faraday/options.rb'
|
|
||||||
- 'lib/faraday/upload_io.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
|
|
||||||
# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
|
|
||||||
Style/TrivialAccessors:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/faraday/utils/headers.rb'
|
|
||||||
|
|
||||||
# Offense count: 2
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Style/UnlessElse:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/faraday/adapter/em_http.rb'
|
|
||||||
- 'lib/faraday/adapter/em_http_ssl_patch.rb'
|
|
||||||
|
|
||||||
# Offense count: 5
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle.
|
|
||||||
# SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only
|
|
||||||
Style/YodaCondition:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/faraday/adapter/net_http.rb'
|
|
||||||
- 'script/proxy-server'
|
|
||||||
- 'test/helper.rb'
|
|
||||||
|
|
||||||
# Offense count: 272
|
|
||||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||||
# URISchemes: http, https
|
# URISchemes: http, https
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
|
@ -107,29 +107,27 @@ module Faraday
|
|||||||
perform_single_request(env)
|
perform_single_request(env)
|
||||||
.callback { env[:response].finish(env) }
|
.callback { env[:response].finish(env) }
|
||||||
}
|
}
|
||||||
|
elsif EventMachine.reactor_running?
|
||||||
|
# EM is running: instruct upstream that this is an async request
|
||||||
|
env[:parallel_manager] = true
|
||||||
|
perform_single_request(env)
|
||||||
|
.callback { env[:response].finish(env) }
|
||||||
|
.errback {
|
||||||
|
# TODO: no way to communicate the error in async mode
|
||||||
|
raise NotImplementedError
|
||||||
|
}
|
||||||
else
|
else
|
||||||
unless EventMachine.reactor_running?
|
error = nil
|
||||||
error = nil
|
# start EM, block until request is completed
|
||||||
# start EM, block until request is completed
|
EventMachine.run do
|
||||||
EventMachine.run do
|
|
||||||
perform_single_request(env)
|
|
||||||
.callback { EventMachine.stop }
|
|
||||||
.errback { |client|
|
|
||||||
error = error_message(client)
|
|
||||||
EventMachine.stop
|
|
||||||
}
|
|
||||||
end
|
|
||||||
raise_error(error) if error
|
|
||||||
else
|
|
||||||
# EM is running: instruct upstream that this is an async request
|
|
||||||
env[:parallel_manager] = true
|
|
||||||
perform_single_request(env)
|
perform_single_request(env)
|
||||||
.callback { env[:response].finish(env) }
|
.callback { EventMachine.stop }
|
||||||
.errback {
|
.errback { |client|
|
||||||
# TODO: no way to communicate the error in async mode
|
error = error_message(client)
|
||||||
raise NotImplementedError
|
EventMachine.stop
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
raise_error(error) if error
|
||||||
end
|
end
|
||||||
rescue EventMachine::Connectify::CONNECTError => err
|
rescue EventMachine::Connectify::CONNECTError => err
|
||||||
if err.message.include?('Proxy Authentication Required')
|
if err.message.include?('Proxy Authentication Required')
|
||||||
|
@ -30,10 +30,10 @@ module EmHttpSslPatch
|
|||||||
def ssl_handshake_completed
|
def ssl_handshake_completed
|
||||||
return true unless verify_peer?
|
return true unless verify_peer?
|
||||||
|
|
||||||
unless OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
|
if OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
|
||||||
raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
|
|
||||||
else
|
|
||||||
true
|
true
|
||||||
|
else
|
||||||
|
raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ module Faraday
|
|||||||
request = Net::HTTPGenericRequest.new \
|
request = Net::HTTPGenericRequest.new \
|
||||||
env[:method].to_s.upcase, # request method
|
env[:method].to_s.upcase, # request method
|
||||||
!!env[:body], # is there request body
|
!!env[:body], # is there request body
|
||||||
:head != env[:method], # is there response body
|
env[:method] != :head, # is there response body
|
||||||
env[:url].request_uri, # request uri path
|
env[:url].request_uri, # request uri path
|
||||||
env[:request_headers] # request headers
|
env[:request_headers] # request headers
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ module Faraday
|
|||||||
end
|
end
|
||||||
|
|
||||||
def perform_request_with_wrapped_block(http, env, &block)
|
def perform_request_with_wrapped_block(http, env, &block)
|
||||||
if (:get == env[:method]) && !env[:body]
|
if (env[:method] == :get) && !env[:body]
|
||||||
# prefer `get` to `request` because the former handles gzip (ruby 1.9)
|
# prefer `get` to `request` because the former handles gzip (ruby 1.9)
|
||||||
request_via_get_method(http, env, &block)
|
request_via_get_method(http, env, &block)
|
||||||
else
|
else
|
||||||
|
@ -10,7 +10,7 @@ module Faraday
|
|||||||
|
|
||||||
def net_http_connection(env)
|
def net_http_connection(env)
|
||||||
@cached_connection ||=
|
@cached_connection ||=
|
||||||
if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
|
if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == %i[key name]
|
||||||
options = { name: 'Faraday' }
|
options = { name: 'Faraday' }
|
||||||
options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
|
options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
|
||||||
Net::HTTP::Persistent.new(options)
|
Net::HTTP::Persistent.new(options)
|
||||||
|
@ -202,7 +202,7 @@ module Faraday
|
|||||||
env[:params] = (query = env[:url].query) ?
|
env[:params] = (query = env[:url].query) ?
|
||||||
params_encoder.decode(query) : {}
|
params_encoder.decode(query) : {}
|
||||||
block_arity = stub.block.arity
|
block_arity = stub.block.arity
|
||||||
status, headers, body = (block_arity >= 0) ?
|
status, headers, body = block_arity >= 0 ?
|
||||||
stub.block.call(*[env, meta].take(block_arity)) :
|
stub.block.call(*[env, meta].take(block_arity)) :
|
||||||
stub.block.call(env, meta)
|
stub.block.call(env, meta)
|
||||||
save_response(env, status, body, headers)
|
save_response(env, status, body, headers)
|
||||||
|
@ -14,7 +14,7 @@ module Faraday
|
|||||||
#
|
#
|
||||||
class Connection
|
class Connection
|
||||||
# A Set of allowed HTTP verbs.
|
# A Set of allowed HTTP verbs.
|
||||||
METHODS = Set.new [:get, :post, :put, :delete, :head, :patch, :options, :trace, :connect]
|
METHODS = Set.new %i[get post put delete head patch options trace connect]
|
||||||
|
|
||||||
# @return [Hash] URI query unencoded key/value pairs.
|
# @return [Hash] URI query unencoded key/value pairs.
|
||||||
attr_reader :params
|
attr_reader :params
|
||||||
|
@ -52,7 +52,7 @@ module Faraday
|
|||||||
other.each do |key, other_value|
|
other.each do |key, other_value|
|
||||||
self_value = send(key)
|
self_value = send(key)
|
||||||
sub_options = self.class.options_for(key)
|
sub_options = self.class.options_for(key)
|
||||||
new_value = (self_value && sub_options && other_value) ? self_value.merge(other_value) : other_value
|
new_value = self_value && sub_options && other_value ? self_value.merge(other_value) : other_value
|
||||||
send("#{key}=", new_value) unless new_value.nil?
|
send("#{key}=", new_value) unless new_value.nil?
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
@ -188,7 +188,7 @@ module Faraday
|
|||||||
end
|
end
|
||||||
|
|
||||||
def symbolized_key_set
|
def symbolized_key_set
|
||||||
@symbolized_key_set ||= Set.new(keys.map { |k| k.to_sym })
|
@symbolized_key_set ||= Set.new(keys.map(&:to_sym))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.inherited(subclass)
|
def self.inherited(subclass)
|
||||||
|
@ -23,7 +23,7 @@ module Faraday
|
|||||||
# interval that is random between 0.1 and 0.15.
|
# interval that is random between 0.1 and 0.15.
|
||||||
class Request::Retry < Faraday::Middleware
|
class Request::Retry < Faraday::Middleware
|
||||||
DEFAULT_EXCEPTIONS = [Errno::ETIMEDOUT, 'Timeout::Error', Faraday::TimeoutError, Faraday::RetriableResponse].freeze
|
DEFAULT_EXCEPTIONS = [Errno::ETIMEDOUT, 'Timeout::Error', Faraday::TimeoutError, Faraday::RetriableResponse].freeze
|
||||||
IDEMPOTENT_METHODS = [:delete, :get, :head, :options, :put]
|
IDEMPOTENT_METHODS = %i[delete get head options put]
|
||||||
|
|
||||||
class Options < Faraday::Options.new(:max, :interval, :max_interval, :interval_randomness,
|
class Options < Faraday::Options.new(:max, :interval, :max_interval, :interval_randomness,
|
||||||
:backoff_factor, :exceptions, :methods, :retry_if, :retry_block,
|
:backoff_factor, :exceptions, :methods, :retry_if, :retry_block,
|
||||||
|
@ -14,7 +14,7 @@ module Faraday
|
|||||||
class CompositeReadIO
|
class CompositeReadIO
|
||||||
def initialize(*parts)
|
def initialize(*parts)
|
||||||
@parts = parts.flatten
|
@parts = parts.flatten
|
||||||
@ios = @parts.map { |part| part.to_io }
|
@ios = @parts.map(&:to_io)
|
||||||
@index = 0
|
@index = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ module Faraday
|
|||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def rewind
|
def rewind
|
||||||
@ios.each { |io| io.rewind }
|
@ios.each(&:rewind)
|
||||||
@index = 0
|
@index = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -49,14 +49,14 @@ module Faraday
|
|||||||
end
|
end
|
||||||
advance_io
|
advance_io
|
||||||
end
|
end
|
||||||
(!got_result && length) ? nil : outbuf
|
!got_result && length ? nil : outbuf
|
||||||
end
|
end
|
||||||
|
|
||||||
# Close each of the IOs.
|
# Close each of the IOs.
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def close
|
def close
|
||||||
@ios.each { |io| io.close }
|
@ios.each(&:close)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_open_and_readable
|
def ensure_open_and_readable
|
||||||
|
@ -42,7 +42,7 @@ module Faraday
|
|||||||
key
|
key
|
||||||
else
|
else
|
||||||
key.to_s.split('_') # user_agent: %w(user agent)
|
key.to_s.split('_') # user_agent: %w(user agent)
|
||||||
.each { |w| w.capitalize! } # => %w(User Agent)
|
.each(&:capitalize!) # => %w(User Agent)
|
||||||
.join('-') # => "User-Agent"
|
.join('-') # => "User-Agent"
|
||||||
end
|
end
|
||||||
keymap_mutex.synchronize { map[key] = value }
|
keymap_mutex.synchronize { map[key] = value }
|
||||||
@ -125,9 +125,7 @@ module Faraday
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def names
|
attr_reader :names
|
||||||
@names
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ webrick_opts = {
|
|||||||
ProxyAuthProc: lambda { |req, res|
|
ProxyAuthProc: lambda { |req, res|
|
||||||
if username
|
if username
|
||||||
type, credentials = req.header['proxy-authorization'].first.to_s.split(/\s+/, 2)
|
type, credentials = req.header['proxy-authorization'].first.to_s.split(/\s+/, 2)
|
||||||
unless 'Basic' == type && match_credentials.call(credentials)
|
unless type == 'Basic' && match_credentials.call(credentials)
|
||||||
res['proxy-authenticate'] = %{Basic realm="testing"}
|
res['proxy-authenticate'] = %{Basic realm="testing"}
|
||||||
raise WEBrick::HTTPStatus::ProxyAuthenticationRequired
|
raise WEBrick::HTTPStatus::ProxyAuthenticationRequired
|
||||||
end
|
end
|
||||||
|
@ -93,7 +93,7 @@ module Faraday
|
|||||||
|
|
||||||
def big_string
|
def big_string
|
||||||
kb = 1024
|
kb = 1024
|
||||||
(32..126).map { |i| i.chr }.cycle.take(50 * kb).join
|
(32..126).map(&:chr).cycle.take(50 * kb).join
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,11 +59,11 @@ module Faraday
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.jruby?
|
def self.jruby?
|
||||||
defined? RUBY_ENGINE && ('jruby' == RUBY_ENGINE)
|
defined? RUBY_ENGINE && (RUBY_ENGINE == 'jruby')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rbx?
|
def self.rbx?
|
||||||
defined? RUBY_ENGINE && ('rbx' == RUBY_ENGINE)
|
defined? RUBY_ENGINE && (RUBY_ENGINE == 'rbx')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ruby_22_plus?
|
def self.ruby_22_plus?
|
||||||
|
@ -9,7 +9,7 @@ module Faraday
|
|||||||
disable :logging
|
disable :logging
|
||||||
disable :protection
|
disable :protection
|
||||||
|
|
||||||
[:get, :post, :put, :patch, :delete, :options].each do |method|
|
%i[get post put patch delete options].each do |method|
|
||||||
send(method, '/echo') do
|
send(method, '/echo') do
|
||||||
kind = request.request_method.downcase
|
kind = request.request_method.downcase
|
||||||
out = kind.dup
|
out = kind.dup
|
||||||
@ -21,7 +21,7 @@ module Faraday
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[:get, :post].each do |method|
|
%i[get post].each do |method|
|
||||||
send(method, '/stream') do
|
send(method, '/stream') do
|
||||||
content_type :txt
|
content_type :txt
|
||||||
stream do |out|
|
stream do |out|
|
||||||
@ -32,7 +32,7 @@ module Faraday
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[:get, :post].each do |method|
|
%i[get post].each do |method|
|
||||||
send(method, '/empty_stream') do
|
send(method, '/empty_stream') do
|
||||||
content_type :txt
|
content_type :txt
|
||||||
stream do |out|
|
stream do |out|
|
||||||
|
@ -4,7 +4,7 @@ module Faraday
|
|||||||
module Shared
|
module Shared
|
||||||
def self.big_string
|
def self.big_string
|
||||||
kb = 1024
|
kb = 1024
|
||||||
(32..126).map { |i| i.chr }.cycle.take(50 * kb).join
|
(32..126).map(&:chr).cycle.take(50 * kb).join
|
||||||
end
|
end
|
||||||
|
|
||||||
def big_string
|
def big_string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user