Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix RuboCop Style/HashSyntax #878

Merged
merged 2 commits into from Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 2 additions & 9 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-02-25 23:59:49 +0100 using RuboCop version 0.65.0.
# on 2019-02-26 09:45:16 +0000 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 @@ -554,13 +554,6 @@ Style/GuardClause:
- 'lib/faraday/request/url_encoded.rb'
- 'lib/faraday/utils/headers.rb'

# Offense count: 154
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Enabled: false

# Offense count: 1
Style/IfInsideElse:
Exclude:
Expand Down Expand Up @@ -957,7 +950,7 @@ Style/YodaCondition:
- 'script/proxy-server'
- 'test/helper.rb'

# Offense count: 279
# Offense count: 273
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
16 changes: 8 additions & 8 deletions Gemfile
Expand Up @@ -4,29 +4,29 @@ source 'https://rubygems.org'

ruby RUBY_VERSION

gem 'ffi-ncurses', '~> 0.3', :platforms => :jruby
gem 'jruby-openssl', '~> 0.8.8', :platforms => :jruby
gem 'ffi-ncurses', '~> 0.3', platforms: :jruby
gem 'jruby-openssl', '~> 0.8.8', platforms: :jruby
gem 'rake'

group :development, :test do
gem 'pry'
end

group :test do
gem 'coveralls', :require => false
gem 'em-http-request', '>= 1.1', :require => 'em-http'
gem 'em-synchrony', '>= 1.0.3', :require => ['em-synchrony', 'em-synchrony/em-http']
gem 'coveralls', require: false
gem 'em-http-request', '>= 1.1', require: 'em-http'
gem 'em-synchrony', '>= 1.0.3', require: ['em-synchrony', 'em-synchrony/em-http']
gem 'excon', '>= 0.27.4'
gem 'httpclient', '>= 2.2'
gem 'minitest', '>= 5.0.5'
gem 'net-http-persistent'
gem 'patron', '>= 0.4.2', :platforms => :ruby
gem 'rack-test', '>= 0.6', :require => 'rack/test'
gem 'patron', '>= 0.4.2', platforms: :ruby
gem 'rack-test', '>= 0.6', require: 'rack/test'
gem 'rspec', '~> 3.7'
gem 'rubocop', '~> 0.65.0'
gem 'simplecov'
gem 'sinatra', '~> 1.3'
gem 'typhoeus', '~> 1.3', :git => 'https://github.com/typhoeus/typhoeus.git', :require => 'typhoeus'
gem 'typhoeus', '~> 1.3', git: 'https://github.com/typhoeus/typhoeus.git', require: 'typhoeus'
gem 'webmock', '~> 3.4'
end

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -5,7 +5,7 @@ require 'rake/testtask'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task :default => :test
task default: :test

desc 'Run all tests'
task :test => [:spec]
task test: [:spec]
20 changes: 10 additions & 10 deletions lib/faraday/adapter.rb
Expand Up @@ -10,16 +10,16 @@ class Adapter
CONTENT_LENGTH = 'Content-Length'

register_middleware File.expand_path('../adapter', __FILE__),
:test => [:Test, 'test'],
:net_http => [:NetHttp, 'net_http'],
:net_http_persistent => [:NetHttpPersistent, 'net_http_persistent'],
:typhoeus => [:Typhoeus, 'typhoeus'],
:patron => [:Patron, 'patron'],
:em_synchrony => [:EMSynchrony, 'em_synchrony'],
:em_http => [:EMHttp, 'em_http'],
:excon => [:Excon, 'excon'],
:rack => [:Rack, 'rack'],
:httpclient => [:HTTPClient, 'httpclient']
test: [:Test, 'test'],
net_http: [:NetHttp, 'net_http'],
net_http_persistent: [:NetHttpPersistent, 'net_http_persistent'],
typhoeus: [:Typhoeus, 'typhoeus'],
patron: [:Patron, 'patron'],
em_synchrony: [:EMSynchrony, 'em_synchrony'],
em_http: [:EMHttp, 'em_http'],
excon: [:Excon, 'excon'],
rack: [:Rack, 'rack'],
httpclient: [:HTTPClient, 'httpclient']

# This module marks an Adapter as supporting parallel requests.
module Parallelism
Expand Down
18 changes: 9 additions & 9 deletions lib/faraday/adapter/em_http.rb
Expand Up @@ -19,8 +19,8 @@ def connection_config(env)

def request_config(env)
options = {
:body => read_body(env),
:head => env[:request_headers]
body: read_body(env),
head: env[:request_headers]
# :keepalive => true,
# :file => 'path/to/file', # stream data off disk
iMacTia marked this conversation as resolved.
Show resolved Hide resolved
}
Expand All @@ -37,9 +37,9 @@ def read_body(env)
def configure_proxy(options, env)
if (proxy = request_options(env)[:proxy])
options[:proxy] = {
:host => proxy[:uri].host,
:port => proxy[:uri].port,
:authorization => [proxy[:user], proxy[:password]]
host: proxy[:uri].host,
port: proxy[:uri].port,
authorization: [proxy[:user], proxy[:password]]
}
end
end
Expand All @@ -48,8 +48,8 @@ def configure_proxy(options, env)
def configure_socket(options, env)
if (bind = request_options(env)[:bind])
options[:bind] = {
:host => bind[:host],
:port => bind[:port]
host: bind[:host],
port: bind[:port]
}
end
end
Expand All @@ -58,8 +58,8 @@ def configure_socket(options, env)
def configure_ssl(options, env)
if env[:url].scheme == 'https' && env[:ssl]
options[:ssl] = {
:cert_chain_file => env[:ssl][:ca_file],
:verify_peer => env[:ssl].fetch(:verify, true)
cert_chain_file: env[:ssl][:ca_file],
verify_peer: env[:ssl].fetch(:verify, true)
}
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/faraday/adapter/em_synchrony/parallel_manager.rb
Expand Up @@ -13,10 +13,10 @@ class ParallelManager
# @param args [Array] the rest of the positional arguments
def add(request, method, *args, &block)
queue << {
:request => request,
:method => method,
:args => args,
:block => block
request: request,
method: method,
args: args,
block: block
}
end

Expand Down
18 changes: 9 additions & 9 deletions lib/faraday/adapter/excon.rb
Expand Up @@ -40,22 +40,22 @@ def call(env)

if req[:proxy]
opts[:proxy] = {
:host => req[:proxy][:uri].host,
:hostname => req[:proxy][:uri].hostname,
:port => req[:proxy][:uri].port,
:scheme => req[:proxy][:uri].scheme,
:user => req[:proxy][:user],
:password => req[:proxy][:password]
host: req[:proxy][:uri].host,
hostname: req[:proxy][:uri].hostname,
port: req[:proxy][:uri].port,
scheme: req[:proxy][:uri].scheme,
user: req[:proxy][:user],
password: req[:proxy][:password]
}
end
end

conn = create_connection(env, opts)

resp = conn.request \
:method => env[:method].to_s.upcase,
:headers => env[:request_headers],
:body => read_body(env)
method: env[:method].to_s.upcase,
headers: env[:request_headers],
body: read_body(env)

if req.stream_response?
warn "Streaming downloads for #{self.class.name} are not yet implemented."
Expand Down
4 changes: 2 additions & 2 deletions lib/faraday/adapter/httpclient.rb
Expand Up @@ -40,8 +40,8 @@ def call(env)
env[:body] = env[:body].read if env[:body].respond_to? :read

resp = client.request env[:method], env[:url],
:body => env[:body],
:header => env[:request_headers]
body: env[:body],
header: env[:request_headers]

if (req = env[:request]).stream_response?
warn "Streaming downloads for #{self.class.name} are not yet implemented."
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/patron.rb
Expand Up @@ -29,7 +29,7 @@ def call(env)

response = begin
data = env[:body] ? env[:body].to_s : nil
session.request(env[:method], env[:url].to_s, env[:request_headers], :data => data)
session.request(env[:method], env[:url].to_s, env[:request_headers], data: data)
rescue Errno::ECONNREFUSED, ::Patron::ConnectionFailed
raise Faraday::ConnectionFailed, $!
end
Expand Down
38 changes: 19 additions & 19 deletions lib/faraday/autoload.rb
Expand Up @@ -55,34 +55,34 @@ def all_loaded_constants
class Adapter
extend AutoloadHelper
autoload_all 'faraday/adapter',
:NetHttp => 'net_http',
:NetHttpPersistent => 'net_http_persistent',
:EMSynchrony => 'em_synchrony',
:EMHttp => 'em_http',
:Typhoeus => 'typhoeus',
:Patron => 'patron',
:Excon => 'excon',
:Test => 'test',
:Rack => 'rack',
:HTTPClient => 'httpclient'
NetHttp: 'net_http',
NetHttpPersistent: 'net_http_persistent',
EMSynchrony: 'em_synchrony',
EMHttp: 'em_http',
Typhoeus: 'typhoeus',
Patron: 'patron',
Excon: 'excon',
Test: 'test',
Rack: 'rack',
HTTPClient: 'httpclient'
end

class Request
extend AutoloadHelper
autoload_all 'faraday/request',
:UrlEncoded => 'url_encoded',
:Multipart => 'multipart',
:Retry => 'retry',
:Authorization => 'authorization',
:BasicAuthentication => 'basic_authentication',
:TokenAuthentication => 'token_authentication',
:Instrumentation => 'instrumentation'
UrlEncoded: 'url_encoded',
Multipart: 'multipart',
Retry: 'retry',
Authorization: 'authorization',
BasicAuthentication: 'basic_authentication',
TokenAuthentication: 'token_authentication',
Instrumentation: 'instrumentation'
end

class Response
extend AutoloadHelper
autoload_all 'faraday/response',
:RaiseError => 'raise_error',
:Logger => 'logger'
RaiseError: 'raise_error',
Logger: 'logger'
end
end
12 changes: 6 additions & 6 deletions lib/faraday/connection.rb
Expand Up @@ -475,7 +475,7 @@ def run_request(method, url, body, headers)
@temp_proxy = proxy_for_request(url)

request = build_request(method) do |req|
req.options = req.options.merge(:proxy => @temp_proxy)
req.options = req.options.merge(proxy: @temp_proxy)
req.url(url) if url
req.headers.update(headers) if headers
req.body = body if body
Expand Down Expand Up @@ -527,11 +527,11 @@ def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
# @return [Faraday::Connection]
def dup
self.class.new(build_exclusive_url,
:headers => headers.dup,
:params => params.dup,
:builder => builder.dup,
:ssl => ssl.dup,
:request => options.dup)
headers: headers.dup,
params: params.dup,
builder: builder.dup,
ssl: ssl.dup,
request: options.dup)
end

# Yields username and password extracted from a URI if they both exist.
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/options/connection_options.rb
Expand Up @@ -4,7 +4,7 @@ module Faraday
class ConnectionOptions < Options.new(:request, :proxy, :ssl, :builder, :url,
:parallel_manager, :params, :headers, :builder_class)

options :request => RequestOptions, :ssl => SSLOptions
options request: RequestOptions, ssl: SSLOptions

memoized(:request) { self.class.options_for(:request).new }

Expand Down
4 changes: 2 additions & 2 deletions lib/faraday/options/env.rb
Expand Up @@ -57,8 +57,8 @@ class Env < Options.new(:method, :request_body, :url, :request, :request_headers
# these requests, the Content-Length header is set to 0.
MethodsWithBodies = Set.new(Faraday::METHODS_WITH_BODY.map(&:to_sym))

options :request => RequestOptions,
:request_headers => Utils::Headers, :response_headers => Utils::Headers
options request: RequestOptions,
request_headers: Utils::Headers, response_headers: Utils::Headers

extend Forwardable

Expand Down
4 changes: 2 additions & 2 deletions lib/faraday/options/proxy_options.rb
Expand Up @@ -8,9 +8,9 @@ class ProxyOptions < Options.new(:uri, :user, :password)
def self.from(value)
case value
when String
value = {:uri => Utils.URI(value)}
value = {uri: Utils.URI(value)}
when URI
value = {:uri => value}
value = {uri: value}
when Hash, Options
if (uri = value.delete(:uri))
value[:uri] = Utils.URI(uri)
Expand Down
26 changes: 13 additions & 13 deletions lib/faraday/request.rb
Expand Up @@ -28,13 +28,13 @@ class Request < Struct.new(:method, :path, :params, :headers, :body, :options)
extend MiddlewareRegistry

register_middleware File.expand_path('../request', __FILE__),
:url_encoded => [:UrlEncoded, 'url_encoded'],
:multipart => [:Multipart, 'multipart'],
:retry => [:Retry, 'retry'],
:authorization => [:Authorization, 'authorization'],
:basic_auth => [:BasicAuthentication, 'basic_authentication'],
:token_auth => [:TokenAuthentication, 'token_authentication'],
:instrumentation => [:Instrumentation, 'instrumentation']
url_encoded: [:UrlEncoded, 'url_encoded'],
multipart: [:Multipart, 'multipart'],
retry: [:Retry, 'retry'],
authorization: [:Authorization, 'authorization'],
basic_auth: [:BasicAuthentication, 'basic_authentication'],
token_auth: [:TokenAuthentication, 'token_authentication'],
instrumentation: [:Instrumentation, 'instrumentation']

# @param request_method [String]
# @yield [request] for block customization, if block given
Expand Down Expand Up @@ -106,12 +106,12 @@ def []=(key, value)
# @return [Hash] the hash ready to be serialized in Marshal.
def marshal_dump
{
:method => method,
:body => body,
:headers => headers,
:path => path,
:params => params,
:options => options
method: method,
body: body,
headers: headers,
path: path,
params: params,
options: options
}
end

Expand Down
8 changes: 4 additions & 4 deletions lib/faraday/response.rb
Expand Up @@ -23,8 +23,8 @@ def on_complete(env)
extend MiddlewareRegistry

register_middleware File.expand_path('../response', __FILE__),
:raise_error => [:RaiseError, 'raise_error'],
:logger => [:Logger, 'logger']
raise_error: [:RaiseError, 'raise_error'],
logger: [:Logger, 'logger']

def initialize(env = nil)
@env = Env.from(env) if env
Expand Down Expand Up @@ -77,8 +77,8 @@ def success?

def to_hash
{
:status => env.status, :body => env.body,
:response_headers => env.response_headers
status: env.status, body: env.body,
response_headers: env.response_headers
}
end

Expand Down