Skip to content

Commit

Permalink
chore: RuboCop lints Style/R* (#910)
Browse files Browse the repository at this point in the history
* Fixes Rubocop Style/RescueStandardError

* Fixes Rubocop Style/RegexpLiteral

* Fixes Rubocop Style/RaiseArgs
  • Loading branch information
iMacTia authored and olleolleolle committed Mar 3, 2019
1 parent ea61fd7 commit d657e3d
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 50 deletions.
34 changes: 1 addition & 33 deletions .rubocop_todo.yml
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/em_http.rb
Expand Up @@ -135,7 +135,7 @@ def perform_request(env)
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
Expand Down
4 changes: 2 additions & 2 deletions lib/faraday/adapter/em_http_ssl_patch.rb
Expand Up @@ -23,7 +23,7 @@ def ssl_verify_peer(cert_string)
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

Expand All @@ -33,7 +33,7 @@ def ssl_handshake_completed
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

Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/em_synchrony.rb
Expand Up @@ -93,7 +93,7 @@ def call(env)
else
raise
end
rescue => err
rescue StandardError => err
if defined?(OpenSSL) && err.is_a?(OpenSSL::SSL::SSLError)
raise Faraday::SSLError, err
else
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/httpclient.rb
Expand Up @@ -60,7 +60,7 @@ def call(env)
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
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/autoload.rb
Expand Up @@ -24,7 +24,7 @@ module AutoloadHelper
#
# @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|
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/connection.rb
Expand Up @@ -506,7 +506,7 @@ def build_request(method)
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
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/middleware_registry.rb
Expand Up @@ -79,7 +79,7 @@ def unregister_middleware(key)
#
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)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/utils/headers.rb
Expand Up @@ -113,7 +113,7 @@ def parse(header_string)
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
Expand Down
10 changes: 5 additions & 5 deletions spec/support/shared_examples/request_method.rb
Expand Up @@ -17,8 +17,8 @@

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
Expand Down Expand Up @@ -102,7 +102,7 @@
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
Expand All @@ -119,12 +119,12 @@
# 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
Expand Down
2 changes: 1 addition & 1 deletion test/adapters/integration.rb
Expand Up @@ -109,7 +109,7 @@ module Common
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
Expand Down
4 changes: 2 additions & 2 deletions test/adapters/test_middleware_test.rb
Expand Up @@ -13,10 +13,10 @@ def setup
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
Expand Down

0 comments on commit d657e3d

Please sign in to comment.