mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-07 00:11:11 -04:00
Merge pull request #909 from lostisland/fix/rubocop-style-s
chore: RuboCop lints Style/S*
This commit is contained in:
commit
ea61fd7e44
@ -6,7 +6,7 @@
|
||||
# Note that changes in the inspected code, or installation of new
|
||||
# versions of RuboCop, may require this file to be generated again.
|
||||
|
||||
# Offense count: 41
|
||||
# Offense count: 40
|
||||
Metrics/AbcSize:
|
||||
Max: 86
|
||||
|
||||
@ -21,7 +21,7 @@ Metrics/BlockLength:
|
||||
Metrics/ClassLength:
|
||||
Max: 216
|
||||
|
||||
# Offense count: 20
|
||||
# Offense count: 19
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 20
|
||||
|
||||
@ -35,7 +35,7 @@ Metrics/MethodLength:
|
||||
Metrics/ModuleLength:
|
||||
Max: 101
|
||||
|
||||
# Offense count: 19
|
||||
# Offense count: 17
|
||||
Metrics/PerceivedComplexity:
|
||||
Max: 21
|
||||
|
||||
@ -138,14 +138,13 @@ Style/ModuleFunction:
|
||||
Exclude:
|
||||
- 'lib/faraday/utils.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
Style/MultilineIfModifier:
|
||||
Exclude:
|
||||
- 'lib/faraday/adapter/em_http.rb'
|
||||
- 'lib/faraday/adapter/em_synchrony.rb'
|
||||
- 'lib/faraday/adapter/net_http_persistent.rb'
|
||||
- 'lib/faraday/adapter/rack.rb'
|
||||
- 'test/adapters/em_http_test.rb'
|
||||
- 'test/helper.rb'
|
||||
|
||||
@ -272,50 +271,6 @@ Style/RescueStandardError:
|
||||
- 'lib/faraday/adapter/em_synchrony.rb'
|
||||
- 'lib/faraday/adapter/httpclient.rb'
|
||||
|
||||
# Offense count: 10
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, Whitelist.
|
||||
# Whitelist: present?, blank?, presence, try, try!
|
||||
Style/SafeNavigation:
|
||||
Exclude:
|
||||
- 'lib/faraday/adapter.rb'
|
||||
- 'lib/faraday/adapter/httpclient.rb'
|
||||
- 'lib/faraday/adapter/net_http.rb'
|
||||
- 'lib/faraday/adapter/patron.rb'
|
||||
- 'lib/faraday/adapter/rack.rb'
|
||||
- 'lib/faraday/connection.rb'
|
||||
- 'lib/faraday/options/proxy_options.rb'
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowIfMethodIsEmpty.
|
||||
Style/SingleLineMethods:
|
||||
Exclude:
|
||||
- 'lib/faraday/adapter.rb'
|
||||
- 'lib/faraday/adapter/em_http.rb'
|
||||
- 'lib/faraday/rack_builder.rb'
|
||||
- 'lib/faraday/utils.rb'
|
||||
- 'spec/support/fake_safe_buffer.rb'
|
||||
- 'test/adapters/em_http_test.rb'
|
||||
- 'test/adapters/em_synchrony_test.rb'
|
||||
- 'test/adapters/rack_test.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: .
|
||||
# SupportedStyles: use_perl_names, use_english_names
|
||||
Style/SpecialGlobalVars:
|
||||
EnforcedStyle: use_perl_names
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: single_quotes, double_quotes
|
||||
Style/StringLiteralsInInterpolation:
|
||||
Exclude:
|
||||
- 'lib/faraday/options/env.rb'
|
||||
- 'spec/faraday/utils_spec.rb'
|
||||
|
||||
# Offense count: 280
|
||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||
# URISchemes: http, https
|
||||
|
@ -24,7 +24,9 @@ module Faraday
|
||||
# This module marks an Adapter as supporting parallel requests.
|
||||
module Parallelism
|
||||
attr_writer :supports_parallel
|
||||
def supports_parallel?() @supports_parallel end
|
||||
def supports_parallel?
|
||||
@supports_parallel
|
||||
end
|
||||
|
||||
def inherited(subclass)
|
||||
super
|
||||
@ -51,7 +53,7 @@ module Faraday
|
||||
def save_response(env, status, body, headers = nil, reason_phrase = nil)
|
||||
env.status = status
|
||||
env.body = body
|
||||
env.reason_phrase = reason_phrase && reason_phrase.to_s.strip
|
||||
env.reason_phrase = reason_phrase&.to_s&.strip
|
||||
env.response_headers = Utils::Headers.new.tap do |response_headers|
|
||||
response_headers.update headers unless headers.nil?
|
||||
yield(response_headers) if block_given?
|
||||
|
@ -206,7 +206,9 @@ module Faraday
|
||||
end
|
||||
|
||||
# @return [Boolean]
|
||||
def running?() @running end
|
||||
def running?
|
||||
@running
|
||||
end
|
||||
|
||||
def add
|
||||
if running?
|
||||
|
@ -78,7 +78,7 @@ module Faraday
|
||||
|
||||
@app.call env
|
||||
rescue Errno::ECONNREFUSED
|
||||
raise Faraday::ConnectionFailed, $!
|
||||
raise Faraday::ConnectionFailed, $ERROR_INFO
|
||||
rescue EventMachine::Connectify::CONNECTError => err
|
||||
if err.message.include?('Proxy Authentication Required')
|
||||
raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
|
||||
|
@ -51,15 +51,15 @@ module Faraday
|
||||
|
||||
@app.call env
|
||||
rescue ::HTTPClient::TimeoutError, Errno::ETIMEDOUT
|
||||
raise Faraday::TimeoutError, $!
|
||||
raise Faraday::TimeoutError, $ERROR_INFO
|
||||
rescue ::HTTPClient::BadResponseError => err
|
||||
if err.message.include?('status 407')
|
||||
raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
|
||||
else
|
||||
raise Faraday::ClientError, $!
|
||||
raise Faraday::ClientError, $ERROR_INFO
|
||||
end
|
||||
rescue Errno::ECONNREFUSED, IOError, SocketError
|
||||
raise Faraday::ConnectionFailed, $!
|
||||
raise Faraday::ConnectionFailed, $ERROR_INFO
|
||||
rescue => err
|
||||
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
|
||||
raise Faraday::SSLError, err
|
||||
@ -112,7 +112,7 @@ module Faraday
|
||||
end
|
||||
|
||||
def configure_client
|
||||
@config_block.call(client) if @config_block
|
||||
@config_block&.call(client)
|
||||
end
|
||||
|
||||
# @param ssl [Hash]
|
||||
|
@ -163,7 +163,7 @@ module Faraday
|
||||
# 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
|
||||
@config_block&.call(http)
|
||||
end
|
||||
|
||||
def ssl_cert_store(ssl)
|
||||
|
@ -12,7 +12,7 @@ module Faraday
|
||||
env[:body] = env[:body].read if env[:body].respond_to? :read
|
||||
|
||||
session = ::Patron::Session.new
|
||||
@config_block.call(session) if @config_block
|
||||
@config_block&.call(session)
|
||||
configure_ssl(session, env[:ssl]) if (env[:url].scheme == 'https') && env[:ssl]
|
||||
|
||||
if (req = env[:request])
|
||||
@ -31,7 +31,7 @@ module Faraday
|
||||
data = env[:body] ? env[:body].to_s : nil
|
||||
session.request(env[:method], env[:url].to_s, env[:request_headers], data: data)
|
||||
rescue Errno::ECONNREFUSED, ::Patron::ConnectionFailed
|
||||
raise Faraday::ConnectionFailed, $!
|
||||
raise Faraday::ConnectionFailed, $ERROR_INFO
|
||||
end
|
||||
|
||||
if (req = env[:request]).stream_response?
|
||||
|
@ -35,11 +35,11 @@ module Faraday
|
||||
'rack.url_scheme' => env[:url].scheme
|
||||
}
|
||||
|
||||
env[:request_headers].each do |name, value|
|
||||
env[:request_headers]&.each do |name, value|
|
||||
name = name.upcase.tr('-', '_')
|
||||
name = "HTTP_#{name}" unless SPECIAL_HEADERS.include? name
|
||||
rack_env[name] = value
|
||||
end if env[:request_headers]
|
||||
end
|
||||
|
||||
timeout = env[:request][:timeout] || env[:request][:open_timeout]
|
||||
response = if timeout
|
||||
|
@ -344,7 +344,7 @@ module Faraday
|
||||
@default_parallel_manager ||= begin
|
||||
adapter = @builder.adapter.klass if @builder.adapter
|
||||
|
||||
if adapter && adapter.respond_to?(:supports_parallel?) && adapter.supports_parallel?
|
||||
if adapter&.respond_to?(:supports_parallel?) && adapter&.supports_parallel?
|
||||
adapter.setup_parallel_manager
|
||||
elsif block_given?
|
||||
yield
|
||||
@ -372,7 +372,7 @@ module Faraday
|
||||
nil
|
||||
end
|
||||
yield
|
||||
@parallel_manager && @parallel_manager.run
|
||||
@parallel_manager&.run
|
||||
ensure
|
||||
@parallel_manager = nil
|
||||
end
|
||||
@ -512,7 +512,7 @@ module Faraday
|
||||
end
|
||||
uri = url ? base + url : base
|
||||
uri.query = params.to_query(params_encoder || options.params_encoder) if params
|
||||
uri.query = nil if uri.query && uri.query.empty?
|
||||
uri.query = nil if uri.query&.empty?
|
||||
uri
|
||||
end
|
||||
|
||||
|
@ -152,7 +152,7 @@ module Faraday
|
||||
unless custom_members.empty?
|
||||
attrs << "@custom=#{custom_members.inspect}"
|
||||
end
|
||||
%(#<#{self.class}#{attrs.join(" ")}>)
|
||||
%(#<#{self.class}#{attrs.join(' ')}>)
|
||||
end
|
||||
|
||||
# @private
|
||||
|
@ -19,7 +19,7 @@ module Faraday
|
||||
super(value)
|
||||
end
|
||||
|
||||
memoized(:user) { uri && uri.user && Utils.unescape(uri.user) }
|
||||
memoized(:password) { uri && uri.password && Utils.unescape(uri.password) }
|
||||
memoized(:user) { uri&.user && Utils.unescape(uri.user) }
|
||||
memoized(:password) { uri&.password && Utils.unescape(uri.password) }
|
||||
end
|
||||
end
|
||||
|
@ -36,9 +36,13 @@ module Faraday
|
||||
@args, @block = args, block
|
||||
end
|
||||
|
||||
def klass() @@constants[@name] end
|
||||
def klass
|
||||
@@constants[@name]
|
||||
end
|
||||
|
||||
def inspect() @name end
|
||||
def inspect
|
||||
@name
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
if other.is_a? Handler
|
||||
|
@ -23,7 +23,9 @@ module Faraday
|
||||
end.tr(' ', '+')
|
||||
end
|
||||
|
||||
def unescape(str) CGI.unescape str.to_s end
|
||||
def unescape(str)
|
||||
CGI.unescape str.to_s
|
||||
end
|
||||
|
||||
DEFAULT_SEP = /[&;] */n
|
||||
|
||||
|
@ -40,7 +40,7 @@ RSpec.describe Faraday::Utils do
|
||||
end
|
||||
|
||||
it 'parses with block' do
|
||||
with_default_uri_parser(->(u) { "booya#{"!" * u.size}" }) do
|
||||
with_default_uri_parser(->(u) { "booya#{'!' * u.size}" }) do
|
||||
expect(normalize(url)).to eq('booya!!!!!!!!!!!!!!!!!!!!!!')
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
# emulates ActiveSupport::SafeBuffer#gsub
|
||||
FakeSafeBuffer = Struct.new(:string) do
|
||||
def to_s; self end
|
||||
def to_s
|
||||
self
|
||||
end
|
||||
|
||||
def gsub(regex)
|
||||
string.gsub(regex) do
|
||||
|
@ -4,7 +4,9 @@ require File.expand_path('integration', __dir__)
|
||||
|
||||
module Adapters
|
||||
class EMHttpTest < Faraday::TestCase
|
||||
def adapter() :em_http end
|
||||
def adapter
|
||||
:em_http
|
||||
end
|
||||
|
||||
Integration.apply(self, :Parallel, :NonStreaming, :ParallelNonStreaming) do
|
||||
# https://github.com/eventmachine/eventmachine/pull/289
|
||||
|
@ -4,7 +4,9 @@ require File.expand_path('integration', __dir__)
|
||||
|
||||
module Adapters
|
||||
class EMSynchronyTest < Faraday::TestCase
|
||||
def adapter() :em_synchrony end
|
||||
def adapter
|
||||
:em_synchrony
|
||||
end
|
||||
|
||||
unless jruby?
|
||||
Integration.apply(self, :Parallel, :NonStreaming, :ParallelNonStreaming) do
|
||||
|
@ -5,7 +5,9 @@ require File.expand_path('../live_server', __dir__)
|
||||
|
||||
module Adapters
|
||||
class RackTest < Faraday::TestCase
|
||||
def adapter() :rack end
|
||||
def adapter
|
||||
:rack
|
||||
end
|
||||
|
||||
def adapter_options
|
||||
[Faraday::LiveServer]
|
||||
|
@ -81,6 +81,6 @@ module Faraday
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
if $PROGRAM_NAME == __FILE__
|
||||
Faraday::LiveServer.run!
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user