Skip to content

Commit

Permalink
chore: Fix RuboCop Style/HashSyntax (#878)
Browse files Browse the repository at this point in the history
* Fixes rubocop Style/HashSyntax issues.

* Fixes rubocop Style/HashSyntax issues in comments as well.
  • Loading branch information
iMacTia authored and olleolleolle committed Feb 26, 2019
1 parent d579431 commit aa4e33f
Show file tree
Hide file tree
Showing 35 changed files with 162 additions and 169 deletions.
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]
6 changes: 3 additions & 3 deletions lib/faraday.rb
Expand Up @@ -72,12 +72,12 @@ class << self
# # => Faraday::Connection to http://faraday.com
#
# @example With an URL argument and an options hash
# Faraday.new 'http://faraday.com', :params => {:page => 1}
# Faraday.new 'http://faraday.com', params: { page: 1 }
# # => Faraday::Connection to http://faraday.com?page=1
#
# @example With everything in an options hash
# Faraday.new :url => 'http://faraday.com',
# :params => {:page => 1}
# Faraday.new url: 'http://faraday.com',
# params: { page: 1 }
# # => Faraday::Connection to http://faraday.com?page=1
def new(url = nil, options = nil, &block)
options = options ? default_connection_options.merge(options) : default_connection_options
Expand Down
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
22 changes: 11 additions & 11 deletions lib/faraday/adapter/em_http.rb
Expand Up @@ -19,10 +19,10 @@ def connection_config(env)

def request_config(env)
options = {
:body => read_body(env),
:head => env[:request_headers]
# :keepalive => true,
# :file => 'path/to/file', # stream data off disk
body: read_body(env),
head: env[:request_headers]
# keepalive: true,
# file: 'path/to/file', # stream data off disk
}
configure_compression(options, env)
options
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
4 changes: 2 additions & 2 deletions lib/faraday/adapter/rack.rb
Expand Up @@ -30,8 +30,8 @@ def initialize(faraday_app, rack_app)
def call(env)
super
rack_env = {
:method => env[:method],
:input => env[:body].respond_to?(:read) ? env[:body].read : env[:body],
method: env[:method],
input: env[:body].respond_to?(:read) ? env[:body].read : env[:body],
'rack.url_scheme' => env[:url].scheme
}

Expand Down
14 changes: 7 additions & 7 deletions lib/faraday/adapter/test.rb
Expand Up @@ -11,29 +11,29 @@ class Adapter
# # return static content
# [200, {'Content-Type' => 'application/json'}, 'hi world']
# end
#
#
# # response with content generated based on request
# stub.get '/showget' do |env|
# [200, {'Content-Type' => 'text/plain'}, env[:method].to_s]
# end
#
#
# # regular expression can be used as matching filter
# stub.get /\A\/items\/(\d+)\z/ do |env, meta|
# # in case regular expression is used an instance of MatchData can be received
# [200, {'Content-Type' => 'text/plain'}, "showing item: #{meta[:match_data][1]}"]
# end
# end
# end
#
#
# resp = test.get '/resource.json'
# resp.body # => 'hi world'
#
#
# resp = test.get '/showget'
# resp.body # => 'get'
#
#
# resp = test.get '/items/1'
# resp.body # => 'showing item: 1'
#
#
# resp = test.get '/items/2'
# resp.body # => 'showing item: 2'
#
Expand All @@ -46,7 +46,7 @@ class NotFound < StandardError
end

def initialize
# {:get => [Stub, Stub]}
# { get: [Stub, Stub] }
@stack, @consumed = {}, {}
yield(self) if block_given?
end
Expand Down
40 changes: 20 additions & 20 deletions lib/faraday/autoload.rb
Expand Up @@ -16,7 +16,7 @@ module AutoloadHelper
# @example
#
# Faraday.autoload_all 'faraday/foo',
# :Bar => 'bar'
# Bar: 'bar'
#
# # requires faraday/foo/bar to load Faraday::Bar.
# Faraday::Bar
Expand Down 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

0 comments on commit aa4e33f

Please sign in to comment.