Merge pull request #898 from lostisland/rubocop/styles

chore: RuboCop Style lints
This commit is contained in:
Olle Jonsson 2019-02-28 18:55:53 +01:00 committed by GitHub
commit 3396561021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 44 additions and 102 deletions

View File

@ -1,6 +1,6 @@
# This configuration was generated by
# `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
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@ -572,61 +572,7 @@ Style/StructInheritance:
- 'lib/faraday/request.rb'
- 'spec/faraday/rack_builder_spec.rb'
# Offense count: 6
# 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
# Offense count: 271
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:

View File

@ -107,29 +107,27 @@ module Faraday
perform_single_request(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
unless EventMachine.reactor_running?
error = nil
# start EM, block until request is completed
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
error = nil
# start EM, block until request is completed
EventMachine.run do
perform_single_request(env)
.callback { env[:response].finish(env) }
.errback {
# TODO: no way to communicate the error in async mode
raise NotImplementedError
.callback { EventMachine.stop }
.errback { |client|
error = error_message(client)
EventMachine.stop
}
end
raise_error(error) if error
end
rescue EventMachine::Connectify::CONNECTError => err
if err.message.include?('Proxy Authentication Required')

View File

@ -30,10 +30,10 @@ module EmHttpSslPatch
def ssl_handshake_completed
return true unless verify_peer?
unless OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
else
if OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
true
else
raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
end
end

View File

@ -70,7 +70,7 @@ module Faraday
request = Net::HTTPGenericRequest.new \
env[:method].to_s.upcase, # request method
!!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[:request_headers] # request headers
@ -103,7 +103,7 @@ module Faraday
end
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)
request_via_get_method(http, env, &block)
else

View File

@ -10,7 +10,7 @@ module Faraday
def net_http_connection(env)
@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[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
Net::HTTP::Persistent.new(options)

View File

@ -202,7 +202,7 @@ module Faraday
env[:params] = (query = env[:url].query) ?
params_encoder.decode(query) : {}
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)
save_response(env, status, body, headers)

View File

@ -14,7 +14,7 @@ module Faraday
#
class Connection
# 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.
attr_reader :params

View File

@ -52,7 +52,7 @@ module Faraday
other.each do |key, other_value|
self_value = send(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?
end
self
@ -188,7 +188,7 @@ module Faraday
end
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
def self.inherited(subclass)

View File

@ -23,7 +23,7 @@ module Faraday
# interval that is random between 0.1 and 0.15.
class Request::Retry < Faraday::Middleware
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,
:backoff_factor, :exceptions, :methods, :retry_if, :retry_block,

View File

@ -14,7 +14,7 @@ module Faraday
class CompositeReadIO
def initialize(*parts)
@parts = parts.flatten
@ios = @parts.map { |part| part.to_io }
@ios = @parts.map(&:to_io)
@index = 0
end
@ -27,7 +27,7 @@ module Faraday
#
# @return [void]
def rewind
@ios.each { |io| io.rewind }
@ios.each(&:rewind)
@index = 0
end
@ -49,14 +49,14 @@ module Faraday
end
advance_io
end
(!got_result && length) ? nil : outbuf
!got_result && length ? nil : outbuf
end
# Close each of the IOs.
#
# @return [void]
def close
@ios.each { |io| io.close }
@ios.each(&:close)
end
def ensure_open_and_readable

View File

@ -42,7 +42,7 @@ module Faraday
key
else
key.to_s.split('_') # user_agent: %w(user agent)
.each { |w| w.capitalize! } # => %w(User Agent)
.each(&:capitalize!) # => %w(User Agent)
.join('-') # => "User-Agent"
end
keymap_mutex.synchronize { map[key] = value }
@ -125,9 +125,7 @@ module Faraday
protected
def names
@names
end
attr_reader :names
private

View File

@ -28,7 +28,7 @@ webrick_opts = {
ProxyAuthProc: lambda { |req, res|
if username
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"}
raise WEBrick::HTTPStatus::ProxyAuthenticationRequired
end

View File

@ -93,7 +93,7 @@ module Faraday
def big_string
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

View File

@ -59,11 +59,11 @@ module Faraday
end
def self.jruby?
defined? RUBY_ENGINE && ('jruby' == RUBY_ENGINE)
defined? RUBY_ENGINE && (RUBY_ENGINE == 'jruby')
end
def self.rbx?
defined? RUBY_ENGINE && ('rbx' == RUBY_ENGINE)
defined? RUBY_ENGINE && (RUBY_ENGINE == 'rbx')
end
def self.ruby_22_plus?

View File

@ -9,7 +9,7 @@ module Faraday
disable :logging
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
kind = request.request_method.downcase
out = kind.dup
@ -21,7 +21,7 @@ module Faraday
end
end
[:get, :post].each do |method|
%i[get post].each do |method|
send(method, '/stream') do
content_type :txt
stream do |out|
@ -32,7 +32,7 @@ module Faraday
end
end
[:get, :post].each do |method|
%i[get post].each do |method|
send(method, '/empty_stream') do
content_type :txt
stream do |out|

View File

@ -4,7 +4,7 @@ module Faraday
module Shared
def self.big_string
kb = 1024
(32..126).map { |i| i.chr }.cycle.take(50 * kb).join
(32..126).map(&:chr).cycle.take(50 * kb).join
end
def big_string