diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7191ec71..5793f659 100644 --- a/.rubocop_todo.yml +++ b/.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 @@ -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 diff --git a/lib/faraday/adapter/em_http.rb b/lib/faraday/adapter/em_http.rb index f121ce3b..65fab218 100644 --- a/lib/faraday/adapter/em_http.rb +++ b/lib/faraday/adapter/em_http.rb @@ -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 diff --git a/lib/faraday/adapter/em_http_ssl_patch.rb b/lib/faraday/adapter/em_http_ssl_patch.rb index d1122302..678ec452 100644 --- a/lib/faraday/adapter/em_http_ssl_patch.rb +++ b/lib/faraday/adapter/em_http_ssl_patch.rb @@ -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 diff --git a/lib/faraday/adapter/em_synchrony.rb b/lib/faraday/adapter/em_synchrony.rb index a82376c8..180d1f91 100644 --- a/lib/faraday/adapter/em_synchrony.rb +++ b/lib/faraday/adapter/em_synchrony.rb @@ -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 diff --git a/lib/faraday/adapter/httpclient.rb b/lib/faraday/adapter/httpclient.rb index 68f2e694..14f2c2a6 100644 --- a/lib/faraday/adapter/httpclient.rb +++ b/lib/faraday/adapter/httpclient.rb @@ -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 diff --git a/lib/faraday/autoload.rb b/lib/faraday/autoload.rb index 9d5a18c7..1e93044b 100644 --- a/lib/faraday/autoload.rb +++ b/lib/faraday/autoload.rb @@ -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| diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index 840ef5ba..fe13034d 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -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 diff --git a/lib/faraday/middleware_registry.rb b/lib/faraday/middleware_registry.rb index 6cf3fd23..a7772d20 100644 --- a/lib/faraday/middleware_registry.rb +++ b/lib/faraday/middleware_registry.rb @@ -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) diff --git a/lib/faraday/utils/headers.rb b/lib/faraday/utils/headers.rb index 6ef9b4fa..bd710853 100644 --- a/lib/faraday/utils/headers.rb +++ b/lib/faraday/utils/headers.rb @@ -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 diff --git a/spec/support/shared_examples/request_method.rb b/spec/support/shared_examples/request_method.rb index 9443d290..2e8b3cc4 100644 --- a/spec/support/shared_examples/request_method.rb +++ b/spec/support/shared_examples/request_method.rb @@ -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 diff --git a/test/adapters/integration.rb b/test/adapters/integration.rb index f29acccf..a2ee71ab 100644 --- a/test/adapters/integration.rb +++ b/test/adapters/integration.rb @@ -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 diff --git a/test/adapters/test_middleware_test.rb b/test/adapters/test_middleware_test.rb index 40734e6d..ed2c8409 100644 --- a/test/adapters/test_middleware_test.rb +++ b/test/adapters/test_middleware_test.rb @@ -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