From 6240672bc84b23339fc9a9878040fcb45db78fb5 Mon Sep 17 00:00:00 2001 From: Nate Holland Date: Wed, 8 May 2019 19:48:50 -0500 Subject: [PATCH] Upgrade RuboCop to v0.68.1 (#549) * Bump to RuboCop latest version and run autocorrect This is the latest version of rubocop with most of the auto-corrects run. There are a few notes on this: - Performance cops have been refactored out so they require being installed in a new gem. That gem has been included so that we can keep performance cops. - I left out the Layout/AlignHash cop because the code base has it going both ways. I want to put that in its own commit so that it is easy to change or reverse if the maintainers want to go one way or another. * Enable Layout/AlignHash and run auto-correct This commit enables Layout/AlignHash and sets the prefered format to the table format. The docs for this cop can be found here: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/AlignHash --- .rubocop.yml | 6 ++++ Gemfile | 3 +- lib/http/chainable.rb | 2 +- lib/http/client.rb | 2 +- lib/http/connection.rb | 8 ++--- lib/http/content_type.rb | 4 +-- lib/http/features/auto_deflate.rb | 12 +++---- lib/http/features/auto_inflate.rb | 10 +++--- lib/http/headers.rb | 4 +-- lib/http/request.rb | 12 +++---- lib/http/request/writer.rb | 4 +-- lib/http/uri.rb | 10 +++--- spec/lib/http/connection_spec.rb | 6 ++-- .../lib/http/features/instrumentation_spec.rb | 12 +++---- spec/lib/http/features/logging_spec.rb | 8 ++--- spec/lib/http/options/merge_spec.rb | 32 +++++++++---------- spec/lib/http/request_spec.rb | 8 ++--- spec/support/dummy_server.rb | 12 +++---- spec/support/http_handling_shared.rb | 8 ++--- spec/support/ssl_helper.rb | 4 +-- 20 files changed, 87 insertions(+), 80 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cbf08415..a046bbc3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,15 @@ +require: rubocop-performance + AllCops: TargetRubyVersion: 2.3 DisplayCopNames: true ## Layout ###################################################################### +Layout/AlignHash: + EnforcedColonStyle: table + EnforcedHashRocketStyle: table + Layout/DotPosition: EnforcedStyle: trailing diff --git a/Gemfile b/Gemfile index 94125230..a8e938bf 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,8 @@ group :test do gem "rspec", "~> 3.0" gem "rspec-its" - gem "rubocop", "= 0.59.2" + gem "rubocop", "= 0.68.1" + gem "rubocop-performance" gem "yardstick" end diff --git a/lib/http/chainable.rb b/lib/http/chainable.rb index b19c9132..941afc65 100644 --- a/lib/http/chainable.rb +++ b/lib/http/chainable.rb @@ -106,7 +106,7 @@ def timeout(options) end branch default_options.merge( - :timeout_class => klass, + :timeout_class => klass, :timeout_options => options ) end diff --git a/lib/http/client.rb b/lib/http/client.rb index e9a8980f..5a5d75c3 100644 --- a/lib/http/client.rb +++ b/lib/http/client.rb @@ -16,7 +16,7 @@ class Client extend Forwardable include Chainable - HTTP_OR_HTTPS_RE = %r{^https?://}i + HTTP_OR_HTTPS_RE = %r{^https?://}i.freeze def initialize(default_options = {}) @default_options = HTTP::Options.new(default_options) diff --git a/lib/http/connection.rb b/lib/http/connection.rb index 15678cf2..0e9082a1 100644 --- a/lib/http/connection.rb +++ b/lib/http/connection.rb @@ -45,8 +45,8 @@ def initialize(req, options) send_proxy_connect_request(req) start_tls(req, options) reset_timer - rescue IOError, SocketError, SystemCallError => ex - raise ConnectionError, "failed to connect: #{ex}", ex.backtrace + rescue IOError, SocketError, SystemCallError => e + raise ConnectionError, "failed to connect: #{e}", e.backtrace end # @see (HTTP::Response::Parser#status_code) @@ -216,8 +216,8 @@ def read_more(size) elsif value @parser << value end - rescue IOError, SocketError, SystemCallError => ex - raise ConnectionError, "error reading from socket: #{ex}", ex.backtrace + rescue IOError, SocketError, SystemCallError => e + raise ConnectionError, "error reading from socket: #{e}", e.backtrace end end end diff --git a/lib/http/content_type.rb b/lib/http/content_type.rb index 51099afe..3ae3d19c 100644 --- a/lib/http/content_type.rb +++ b/lib/http/content_type.rb @@ -2,8 +2,8 @@ module HTTP ContentType = Struct.new(:mime_type, :charset) do - MIME_TYPE_RE = %r{^([^/]+/[^;]+)(?:$|;)} - CHARSET_RE = /;\s*charset=([^;]+)/i + MIME_TYPE_RE = %r{^([^/]+/[^;]+)(?:$|;)}.freeze + CHARSET_RE = /;\s*charset=([^;]+)/i.freeze class << self # Parse string and return ContentType struct diff --git a/lib/http/features/auto_deflate.rb b/lib/http/features/auto_deflate.rb index 98972927..4b9b75c3 100644 --- a/lib/http/features/auto_deflate.rb +++ b/lib/http/features/auto_deflate.rb @@ -27,12 +27,12 @@ def wrap_request(request) request.headers[Headers::CONTENT_ENCODING] = method Request.new( - :version => request.version, - :verb => request.verb, - :uri => request.uri, - :headers => request.headers, - :proxy => request.proxy, - :body => deflated_body(request.body), + :version => request.version, + :verb => request.verb, + :uri => request.uri, + :headers => request.headers, + :proxy => request.proxy, + :body => deflated_body(request.body), :uri_normalizer => request.uri_normalizer ) end diff --git a/lib/http/features/auto_inflate.rb b/lib/http/features/auto_inflate.rb index 38066708..e94a1324 100644 --- a/lib/http/features/auto_inflate.rb +++ b/lib/http/features/auto_inflate.rb @@ -12,12 +12,12 @@ def wrap_response(response) return response unless supported_encoding?(response) options = { - :status => response.status, - :version => response.version, - :headers => response.headers, + :status => response.status, + :version => response.version, + :headers => response.headers, :proxy_headers => response.proxy_headers, - :connection => response.connection, - :body => stream_for(response.connection) + :connection => response.connection, + :body => stream_for(response.connection) } options[:uri] = response.uri if response.uri diff --git a/lib/http/headers.rb b/lib/http/headers.rb index 3c820d8c..de3f6ced 100644 --- a/lib/http/headers.rb +++ b/lib/http/headers.rb @@ -13,11 +13,11 @@ class Headers include Enumerable # Matches HTTP header names when in "Canonical-Http-Format" - CANONICAL_NAME_RE = /\A[A-Z][a-z]*(?:-[A-Z][a-z]*)*\z/ + CANONICAL_NAME_RE = /\A[A-Z][a-z]*(?:-[A-Z][a-z]*)*\z/.freeze # Matches valid header field name according to RFC. # @see http://tools.ietf.org/html/rfc7230#section-3.2 - COMPLIANT_NAME_RE = /\A[A-Za-z0-9!#\$%&'*+\-.^_`|~]+\z/ + COMPLIANT_NAME_RE = /\A[A-Za-z0-9!#\$%&'*+\-.^_`|~]+\z/.freeze # Class constructor. def initialize diff --git a/lib/http/request.rb b/lib/http/request.rb index 5a2bf991..4f6286b9 100644 --- a/lib/http/request.rb +++ b/lib/http/request.rb @@ -54,10 +54,10 @@ class UnsupportedSchemeError < RequestError; end # Default ports of supported schemes PORTS = { - :http => 80, - :https => 443, - :ws => 80, - :wss => 443 + :http => 80, + :https => 443, + :ws => 80, + :wss => 443 }.freeze # Method is given as a lowercase symbol e.g. :get, :post @@ -168,8 +168,8 @@ def proxy_connect_header # Headers to send with proxy connect request def proxy_connect_headers connect_headers = HTTP::Headers.coerce( - Headers::HOST => headers[Headers::HOST], - Headers::USER_AGENT => headers[Headers::USER_AGENT] + Headers::HOST => headers[Headers::HOST], + Headers::USER_AGENT => headers[Headers::USER_AGENT] ) connect_headers[Headers::PROXY_AUTHORIZATION] = proxy_authorization_header if using_authenticated_proxy? diff --git a/lib/http/request/writer.rb b/lib/http/request/writer.rb index c90c11e7..9f75028b 100644 --- a/lib/http/request/writer.rb +++ b/lib/http/request/writer.rb @@ -113,8 +113,8 @@ def write(data) end rescue Errno::EPIPE raise - rescue IOError, SocketError, SystemCallError => ex - raise ConnectionError, "error writing to socket: #{ex}", ex.backtrace + rescue IOError, SocketError, SystemCallError => e + raise ConnectionError, "error writing to socket: #{e}", e.backtrace end end end diff --git a/lib/http/uri.rb b/lib/http/uri.rb index eafd1e98..f694ed08 100644 --- a/lib/http/uri.rb +++ b/lib/http/uri.rb @@ -31,11 +31,11 @@ class URI uri = HTTP::URI.parse uri HTTP::URI.new( - :scheme => uri.normalized_scheme, - :authority => uri.normalized_authority, - :path => uri.normalized_path, - :query => uri.query, - :fragment => uri.normalized_fragment + :scheme => uri.normalized_scheme, + :authority => uri.normalized_authority, + :path => uri.normalized_path, + :query => uri.query, + :fragment => uri.normalized_fragment ) end diff --git a/spec/lib/http/connection_spec.rb b/spec/lib/http/connection_spec.rb index f6dec7f7..3e54322c 100644 --- a/spec/lib/http/connection_spec.rb +++ b/spec/lib/http/connection_spec.rb @@ -3,9 +3,9 @@ RSpec.describe HTTP::Connection do let(:req) do HTTP::Request.new( - :verb => :get, - :uri => "http://example.com/", - :headers => {} + :verb => :get, + :uri => "http://example.com/", + :headers => {} ) end let(:socket) { double(:connect => nil) } diff --git a/spec/lib/http/features/instrumentation_spec.rb b/spec/lib/http/features/instrumentation_spec.rb index a15d2e2c..c382093b 100644 --- a/spec/lib/http/features/instrumentation_spec.rb +++ b/spec/lib/http/features/instrumentation_spec.rb @@ -7,10 +7,10 @@ describe "logging the request" do let(:request) do HTTP::Request.new( - :verb => :post, - :uri => "https://example.com/", + :verb => :post, + :uri => "https://example.com/", :headers => {:accept => "application/json"}, - :body => '{"hello": "world!"}' + :body => '{"hello": "world!"}' ) end @@ -25,10 +25,10 @@ let(:response) do HTTP::Response.new( :version => "1.1", - :uri => "https://example.com", - :status => 200, + :uri => "https://example.com", + :status => 200, :headers => {:content_type => "application/json"}, - :body => '{"success": true}' + :body => '{"success": true}' ) end diff --git a/spec/lib/http/features/logging_spec.rb b/spec/lib/http/features/logging_spec.rb index fc19c875..30b2fc53 100644 --- a/spec/lib/http/features/logging_spec.rb +++ b/spec/lib/http/features/logging_spec.rb @@ -17,10 +17,10 @@ describe "logging the request" do let(:request) do HTTP::Request.new( - :verb => :post, - :uri => "https://example.com/", - :headers => {:accept => "application/json"}, - :body => '{"hello": "world!"}' + :verb => :post, + :uri => "https://example.com/", + :headers => {:accept => "application/json"}, + :body => '{"hello": "world!"}' ) end diff --git a/spec/lib/http/options/merge_spec.rb b/spec/lib/http/options/merge_spec.rb index c3495a28..ea09a443 100644 --- a/spec/lib/http/options/merge_spec.rb +++ b/spec/lib/http/options/merge_spec.rb @@ -18,28 +18,28 @@ # FIXME: yuck :( foo = HTTP::Options.new( - :response => :body, - :params => {:baz => "bar"}, - :form => {:foo => "foo"}, - :body => "body-foo", - :json => {:foo => "foo"}, - :headers => {:accept => "json", :foo => "foo"}, - :proxy => {}, - :features => {} + :response => :body, + :params => {:baz => "bar"}, + :form => {:foo => "foo"}, + :body => "body-foo", + :json => {:foo => "foo"}, + :headers => {:accept => "json", :foo => "foo"}, + :proxy => {}, + :features => {} ) bar = HTTP::Options.new( - :response => :parsed_body, - :persistent => "https://www.googe.com", - :params => {:plop => "plip"}, - :form => {:bar => "bar"}, - :body => "body-bar", - :json => {:bar => "bar"}, + :response => :parsed_body, + :persistent => "https://www.googe.com", + :params => {:plop => "plip"}, + :form => {:bar => "bar"}, + :body => "body-bar", + :json => {:bar => "bar"}, :keep_alive_timeout => 10, :headers => {:accept => "xml", :bar => "bar"}, :timeout_options => {:foo => :bar}, - :ssl => {:foo => "bar"}, - :proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080} + :ssl => {:foo => "bar"}, + :proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080} ) expect(foo.merge(bar).to_hash).to eq( diff --git a/spec/lib/http/request_spec.rb b/spec/lib/http/request_spec.rb index b3dc10ed..da4ba074 100644 --- a/spec/lib/http/request_spec.rb +++ b/spec/lib/http/request_spec.rb @@ -8,10 +8,10 @@ subject :request do HTTP::Request.new( - :verb => :get, - :uri => request_uri, - :headers => headers, - :proxy => proxy + :verb => :get, + :uri => request_uri, + :headers => headers, + :proxy => proxy ) end diff --git a/spec/support/dummy_server.rb b/spec/support/dummy_server.rb index 51841ca6..baea6c0a 100644 --- a/spec/support/dummy_server.rb +++ b/spec/support/dummy_server.rb @@ -13,15 +13,15 @@ class DummyServer < WEBrick::HTTPServer include ServerConfig CONFIG = { - :BindAddress => "127.0.0.1", - :Port => 0, - :AccessLog => BlackHole, - :Logger => BlackHole + :BindAddress => "127.0.0.1", + :Port => 0, + :AccessLog => BlackHole, + :Logger => BlackHole }.freeze SSL_CONFIG = CONFIG.merge( - :SSLEnable => true, - :SSLStartImmediately => true + :SSLEnable => true, + :SSLStartImmediately => true ).freeze def initialize(options = {}) # rubocop:disable Style/OptionHash diff --git a/spec/support/http_handling_shared.rb b/spec/support/http_handling_shared.rb index ce8c7ff9..b01d366d 100644 --- a/spec/support/http_handling_shared.rb +++ b/spec/support/http_handling_shared.rb @@ -14,11 +14,11 @@ let(:options) do { - :timeout_class => HTTP::Timeout::PerOperation, + :timeout_class => HTTP::Timeout::PerOperation, :timeout_options => { :connect_timeout => conn_timeout, - :read_timeout => read_timeout, - :write_timeout => write_timeout + :read_timeout => read_timeout, + :write_timeout => write_timeout } } end @@ -62,7 +62,7 @@ context "with a global timeout" do let(:options) do { - :timeout_class => HTTP::Timeout::Global, + :timeout_class => HTTP::Timeout::Global, :timeout_options => { :global_timeout => global_timeout } diff --git a/spec/support/ssl_helper.rb b/spec/support/ssl_helper.rb index b475b766..d3bb7418 100644 --- a/spec/support/ssl_helper.rb +++ b/spec/support/ssl_helper.rb @@ -83,8 +83,8 @@ def client_context def client_params { - :key => client_cert.key, - :cert => client_cert.cert, + :key => client_cert.key, + :cert => client_cert.cert, :ca_file => ca.file } end