chore: RuboCop lints Style/R* (#910)

* Fixes Rubocop Style/RescueStandardError

* Fixes Rubocop Style/RegexpLiteral

* Fixes Rubocop Style/RaiseArgs
This commit is contained in:
Mattia 2019-03-03 09:50:49 +00:00 committed by Olle Jonsson
parent ea61fd7e44
commit d657e3d3c3
12 changed files with 18 additions and 50 deletions

View File

@ -1,6 +1,6 @@
# This configuration was generated by
# `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
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@ -239,38 +239,6 @@ Style/Proc:
- 'spec/support/shared_examples/request_method.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
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https

View File

@ -135,7 +135,7 @@ module Faraday
else
raise Faraday::ConnectionFailed, err
end
rescue => err
rescue StandardError => err
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
raise Faraday::SSLError, err
else

View File

@ -23,7 +23,7 @@ module EmHttpSslPatch
end
true
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
@ -33,7 +33,7 @@ module EmHttpSslPatch
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))
raise OpenSSL::SSL::SSLError, %(host "#{host}" does not match the server certificate)
end
end

View File

@ -93,7 +93,7 @@ module Faraday
else
raise
end
rescue => err
rescue StandardError => err
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
raise Faraday::SSLError, err
else

View File

@ -60,7 +60,7 @@ module Faraday
end
rescue Errno::ECONNREFUSED, IOError, SocketError
raise Faraday::ConnectionFailed, $ERROR_INFO
rescue => err
rescue StandardError => err
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
raise Faraday::SSLError, err
else

View File

@ -24,7 +24,7 @@ module Faraday
#
# @return [void]
def autoload_all(prefix, options)
if prefix =~ /^faraday(\/|$)/i
if prefix =~ %r{^faraday(/|$)}i
prefix = File.join(Faraday.root_path, prefix)
end
options.each do |const_name, path|

View File

@ -506,7 +506,7 @@ module Faraday
def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
url = nil if url.respond_to?(:empty?) && url.empty?
base = url_prefix
if url && base.path && base.path !~ /\/$/
if url && base.path && base.path !~ %r{/$}
base = base.dup
base.path = base.path + '/' # ensure trailing slash
end

View File

@ -79,7 +79,7 @@ module Faraday
#
def lookup_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
def middleware_mutex(&block)

View File

@ -113,7 +113,7 @@ module Faraday
headers = header_string.split(/\r\n/)
# 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

View File

@ -17,8 +17,8 @@ shared_examples 'a request method' do |http_method|
it 'retrieves the response headers' do
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(/text\/plain/)
expect(response.headers['Content-Type']).to match(%r{text/plain})
expect(response.headers['content-type']).to match(%r{text/plain})
end
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|
# WebMock does not support matching body for multipart/form-data requests yet :(
# https://github.com/bblimke/webmock/issues/623
request.body =~ %r{RubyMultipartPost}
request.body =~ /RubyMultipartPost/
end
conn.public_send(http_method, '/', payload)
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.
unless http_method == :head
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, '/')
end
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, '/')
end
end

View File

@ -109,7 +109,7 @@ module Adapters
def_delegators :create_connection, :get, :head, :put, :post, :patch, :delete, :run_request
def adapter
raise NotImplementedError.new('Need to override #adapter')
raise NotImplementedError, 'Need to override #adapter'
end
# extra options to pass when building the adapter

View File

@ -13,10 +13,10 @@ module Adapters
stub.get('/method-echo') do |env|
[200, { 'Content-Type' => 'text/html' }, env[:method].to_s]
end
stub.get(/\A\/resources\/\d+(?:\?|\z)/) do
stub.get(%r{\A/resources/\d+(?:\?|\z)}) do
[200, { 'Content-Type' => 'text/html' }, 'show']
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]}"]
end
stub.get('http://domain.test/hello') do