mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-19 00:04:27 -04:00
chore: RuboCop lints Style/R* (#910)
* Fixes Rubocop Style/RescueStandardError * Fixes Rubocop Style/RegexpLiteral * Fixes Rubocop Style/RaiseArgs
This commit is contained in:
parent
ea61fd7e44
commit
d657e3d3c3
@ -1,6 +1,6 @@
|
|||||||
# This configuration was generated by
|
# This configuration was generated by
|
||||||
# `rubocop --auto-gen-config`
|
# `rubocop --auto-gen-config`
|
||||||
# on 2019-03-03 15:58:42 +0900 using RuboCop version 0.65.0.
|
# on 2019-03-03 10:30:09 +0100 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
|
||||||
@ -239,38 +239,6 @@ Style/Proc:
|
|||||||
- 'spec/support/shared_examples/request_method.rb'
|
- 'spec/support/shared_examples/request_method.rb'
|
||||||
- 'test/adapters/integration.rb'
|
- 'test/adapters/integration.rb'
|
||||||
|
|
||||||
# Offense count: 4
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle.
|
|
||||||
# SupportedStyles: compact, exploded
|
|
||||||
Style/RaiseArgs:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/faraday/adapter/em_http_ssl_patch.rb'
|
|
||||||
- 'lib/faraday/middleware_registry.rb'
|
|
||||||
- 'test/adapters/integration.rb'
|
|
||||||
|
|
||||||
# Offense count: 10
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
|
|
||||||
# SupportedStyles: slashes, percent_r, mixed
|
|
||||||
Style/RegexpLiteral:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/faraday/autoload.rb'
|
|
||||||
- 'lib/faraday/connection.rb'
|
|
||||||
- 'lib/faraday/utils/headers.rb'
|
|
||||||
- 'spec/support/shared_examples/request_method.rb'
|
|
||||||
- 'test/adapters/test_middleware_test.rb'
|
|
||||||
|
|
||||||
# Offense count: 3
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle.
|
|
||||||
# SupportedStyles: implicit, explicit
|
|
||||||
Style/RescueStandardError:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/faraday/adapter/em_http.rb'
|
|
||||||
- 'lib/faraday/adapter/em_synchrony.rb'
|
|
||||||
- 'lib/faraday/adapter/httpclient.rb'
|
|
||||||
|
|
||||||
# Offense count: 280
|
# Offense count: 280
|
||||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||||
# URISchemes: http, https
|
# URISchemes: http, https
|
||||||
|
@ -135,7 +135,7 @@ module Faraday
|
|||||||
else
|
else
|
||||||
raise Faraday::ConnectionFailed, err
|
raise Faraday::ConnectionFailed, err
|
||||||
end
|
end
|
||||||
rescue => err
|
rescue StandardError => err
|
||||||
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
|
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
|
||||||
raise Faraday::SSLError, err
|
raise Faraday::SSLError, err
|
||||||
else
|
else
|
||||||
|
@ -23,7 +23,7 @@ module EmHttpSslPatch
|
|||||||
end
|
end
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
raise OpenSSL::SSL::SSLError.new(%(unable to verify the server certificate for "#{host}"))
|
raise OpenSSL::SSL::SSLError, %(unable to verify the server certificate for "#{host}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ module EmHttpSslPatch
|
|||||||
if OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
|
if OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
|
raise OpenSSL::SSL::SSLError, %(host "#{host}" does not match the server certificate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ module Faraday
|
|||||||
else
|
else
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
rescue => err
|
rescue StandardError => err
|
||||||
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
|
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
|
||||||
raise Faraday::SSLError, err
|
raise Faraday::SSLError, err
|
||||||
else
|
else
|
||||||
|
@ -60,7 +60,7 @@ module Faraday
|
|||||||
end
|
end
|
||||||
rescue Errno::ECONNREFUSED, IOError, SocketError
|
rescue Errno::ECONNREFUSED, IOError, SocketError
|
||||||
raise Faraday::ConnectionFailed, $ERROR_INFO
|
raise Faraday::ConnectionFailed, $ERROR_INFO
|
||||||
rescue => err
|
rescue StandardError => err
|
||||||
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
|
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
|
||||||
raise Faraday::SSLError, err
|
raise Faraday::SSLError, err
|
||||||
else
|
else
|
||||||
|
@ -24,7 +24,7 @@ module Faraday
|
|||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def autoload_all(prefix, options)
|
def autoload_all(prefix, options)
|
||||||
if prefix =~ /^faraday(\/|$)/i
|
if prefix =~ %r{^faraday(/|$)}i
|
||||||
prefix = File.join(Faraday.root_path, prefix)
|
prefix = File.join(Faraday.root_path, prefix)
|
||||||
end
|
end
|
||||||
options.each do |const_name, path|
|
options.each do |const_name, path|
|
||||||
|
@ -506,7 +506,7 @@ module Faraday
|
|||||||
def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
|
def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
|
||||||
url = nil if url.respond_to?(:empty?) && url.empty?
|
url = nil if url.respond_to?(:empty?) && url.empty?
|
||||||
base = url_prefix
|
base = url_prefix
|
||||||
if url && base.path && base.path !~ /\/$/
|
if url && base.path && base.path !~ %r{/$}
|
||||||
base = base.dup
|
base = base.dup
|
||||||
base.path = base.path + '/' # ensure trailing slash
|
base.path = base.path + '/' # ensure trailing slash
|
||||||
end
|
end
|
||||||
|
@ -79,7 +79,7 @@ module Faraday
|
|||||||
#
|
#
|
||||||
def lookup_middleware(key)
|
def lookup_middleware(key)
|
||||||
load_middleware(key) ||
|
load_middleware(key) ||
|
||||||
raise(Faraday::Error.new("#{key.inspect} is not registered on #{self}"))
|
raise(Faraday::Error, "#{key.inspect} is not registered on #{self}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def middleware_mutex(&block)
|
def middleware_mutex(&block)
|
||||||
|
@ -113,7 +113,7 @@ module Faraday
|
|||||||
headers = header_string.split(/\r\n/)
|
headers = header_string.split(/\r\n/)
|
||||||
|
|
||||||
# Find the last set of response headers.
|
# Find the last set of response headers.
|
||||||
start_index = headers.rindex { |x| x.match(/^HTTP\//) } || 0
|
start_index = headers.rindex { |x| x.match(%r{^HTTP/}) } || 0
|
||||||
last_response = headers.slice(start_index, headers.size)
|
last_response = headers.slice(start_index, headers.size)
|
||||||
|
|
||||||
last_response
|
last_response
|
||||||
|
@ -17,8 +17,8 @@ shared_examples 'a request method' do |http_method|
|
|||||||
|
|
||||||
it 'retrieves the response headers' do
|
it 'retrieves the response headers' do
|
||||||
request_stub.to_return(headers: { 'Content-Type' => 'text/plain' })
|
request_stub.to_return(headers: { 'Content-Type' => 'text/plain' })
|
||||||
expect(response.headers['Content-Type']).to match(/text\/plain/)
|
expect(response.headers['Content-Type']).to match(%r{text/plain})
|
||||||
expect(response.headers['content-type']).to match(/text\/plain/)
|
expect(response.headers['content-type']).to match(%r{text/plain})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sends user agent' do
|
it 'sends user agent' do
|
||||||
@ -102,7 +102,7 @@ shared_examples 'a request method' do |http_method|
|
|||||||
request_stub.with(headers: { 'Content-Type' => %r{\Amultipart/form-data} }) do |request|
|
request_stub.with(headers: { 'Content-Type' => %r{\Amultipart/form-data} }) do |request|
|
||||||
# WebMock does not support matching body for multipart/form-data requests yet :(
|
# WebMock does not support matching body for multipart/form-data requests yet :(
|
||||||
# https://github.com/bblimke/webmock/issues/623
|
# https://github.com/bblimke/webmock/issues/623
|
||||||
request.body =~ %r{RubyMultipartPost}
|
request.body =~ /RubyMultipartPost/
|
||||||
end
|
end
|
||||||
conn.public_send(http_method, '/', payload)
|
conn.public_send(http_method, '/', payload)
|
||||||
end
|
end
|
||||||
@ -119,12 +119,12 @@ shared_examples 'a request method' do |http_method|
|
|||||||
# Accept-Encoding header not sent for HEAD requests as body is not expected in the response.
|
# Accept-Encoding header not sent for HEAD requests as body is not expected in the response.
|
||||||
unless http_method == :head
|
unless http_method == :head
|
||||||
it 'handles gzip compression' do
|
it 'handles gzip compression' do
|
||||||
request_stub.with(headers: { 'Accept-Encoding' => %r{\bgzip\b} })
|
request_stub.with(headers: { 'Accept-Encoding' => /\bgzip\b/ })
|
||||||
conn.public_send(http_method, '/')
|
conn.public_send(http_method, '/')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles deflate compression' do
|
it 'handles deflate compression' do
|
||||||
request_stub.with(headers: { 'Accept-Encoding' => %r{\bdeflate\b} })
|
request_stub.with(headers: { 'Accept-Encoding' => /\bdeflate\b/ })
|
||||||
conn.public_send(http_method, '/')
|
conn.public_send(http_method, '/')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -109,7 +109,7 @@ module Adapters
|
|||||||
def_delegators :create_connection, :get, :head, :put, :post, :patch, :delete, :run_request
|
def_delegators :create_connection, :get, :head, :put, :post, :patch, :delete, :run_request
|
||||||
|
|
||||||
def adapter
|
def adapter
|
||||||
raise NotImplementedError.new('Need to override #adapter')
|
raise NotImplementedError, 'Need to override #adapter'
|
||||||
end
|
end
|
||||||
|
|
||||||
# extra options to pass when building the adapter
|
# extra options to pass when building the adapter
|
||||||
|
@ -13,10 +13,10 @@ module Adapters
|
|||||||
stub.get('/method-echo') do |env|
|
stub.get('/method-echo') do |env|
|
||||||
[200, { 'Content-Type' => 'text/html' }, env[:method].to_s]
|
[200, { 'Content-Type' => 'text/html' }, env[:method].to_s]
|
||||||
end
|
end
|
||||||
stub.get(/\A\/resources\/\d+(?:\?|\z)/) do
|
stub.get(%r{\A/resources/\d+(?:\?|\z)}) do
|
||||||
[200, { 'Content-Type' => 'text/html' }, 'show']
|
[200, { 'Content-Type' => 'text/html' }, 'show']
|
||||||
end
|
end
|
||||||
stub.get(/\A\/resources\/(specified)\z/) do |_env, meta|
|
stub.get(%r{\A/resources/(specified)\z}) do |_env, meta|
|
||||||
[200, { 'Content-Type' => 'text/html' }, "show #{meta[:match_data][1]}"]
|
[200, { 'Content-Type' => 'text/html' }, "show #{meta[:match_data][1]}"]
|
||||||
end
|
end
|
||||||
stub.get('http://domain.test/hello') do
|
stub.get('http://domain.test/hello') do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user