Skip to content

Commit

Permalink
Upgrade RuboCop to v0.68.1 (#549)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
natesholland authored and ixti committed May 9, 2019
1 parent fec85f6 commit 6240672
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 80 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
require: rubocop-performance

AllCops:
TargetRubyVersion: 2.3
DisplayCopNames: true

## Layout ######################################################################

Layout/AlignHash:
EnforcedColonStyle: table
EnforcedHashRocketStyle: table

Layout/DotPosition:
EnforcedStyle: trailing

Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/http/chainable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def timeout(options)
end

branch default_options.merge(
:timeout_class => klass,
:timeout_class => klass,
:timeout_options => options
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/http/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/http/content_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/http/features/auto_deflate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/http/features/auto_inflate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/http/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions lib/http/request/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/http/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/lib/http/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/http/features/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions spec/lib/http/features/logging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 16 additions & 16 deletions spec/lib/http/options/merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/http/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions spec/support/dummy_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/support/http_handling_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions spec/support/ssl_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6240672

Please sign in to comment.