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: RuboCop Style lints #898

Merged
merged 6 commits into from Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
58 changes: 2 additions & 56 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-02-27 21:48:38 +0100 using RuboCop version 0.65.0.
# on 2019-02-28 17:29:46 +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 @@ -572,61 +572,7 @@ Style/StructInheritance:
- 'lib/faraday/request.rb'
- 'spec/faraday/rack_builder_spec.rb'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: MinSize.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- 'lib/faraday/options.rb'
- 'lib/faraday/upload_io.rb'
- 'lib/faraday/utils/headers.rb'
- 'spec/support/helper_methods.rb'
- 'test/shared.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
Style/TernaryParentheses:
Exclude:
- 'lib/faraday/adapter/test.rb'
- 'lib/faraday/options.rb'
- 'lib/faraday/upload_io.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
Style/TrivialAccessors:
Exclude:
- 'lib/faraday/utils/headers.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/UnlessElse:
Exclude:
- 'lib/faraday/adapter/em_http.rb'
- 'lib/faraday/adapter/em_http_ssl_patch.rb'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only
Style/YodaCondition:
Exclude:
- 'lib/faraday/adapter/net_http.rb'
- 'script/proxy-server'
- 'test/helper.rb'

# Offense count: 272
# Offense count: 271
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
36 changes: 17 additions & 19 deletions lib/faraday/adapter/em_http.rb
Expand Up @@ -107,29 +107,27 @@ def perform_request(env)
perform_single_request(env)
.callback { env[:response].finish(env) }
}
elsif EventMachine.reactor_running?
# EM is running: instruct upstream that this is an async request
env[:parallel_manager] = true
perform_single_request(env)
.callback { env[:response].finish(env) }
.errback {
# TODO: no way to communicate the error in async mode
raise NotImplementedError
}
else
unless EventMachine.reactor_running?
error = nil
# start EM, block until request is completed
EventMachine.run do
perform_single_request(env)
.callback { EventMachine.stop }
.errback { |client|
error = error_message(client)
EventMachine.stop
}
end
raise_error(error) if error
else
# EM is running: instruct upstream that this is an async request
env[:parallel_manager] = true
error = nil
# start EM, block until request is completed
EventMachine.run do
perform_single_request(env)
.callback { env[:response].finish(env) }
.errback {
# TODO: no way to communicate the error in async mode
raise NotImplementedError
.callback { EventMachine.stop }
.errback { |client|
error = error_message(client)
EventMachine.stop
}
end
raise_error(error) if error
end
rescue EventMachine::Connectify::CONNECTError => err
if err.message.include?('Proxy Authentication Required')
Expand Down
6 changes: 3 additions & 3 deletions lib/faraday/adapter/em_http_ssl_patch.rb
Expand Up @@ -30,10 +30,10 @@ def ssl_verify_peer(cert_string)
def ssl_handshake_completed
return true unless verify_peer?

unless OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
else
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))
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/faraday/adapter/net_http.rb
Expand Up @@ -70,7 +70,7 @@ def create_request(env)
request = Net::HTTPGenericRequest.new \
env[:method].to_s.upcase, # request method
!!env[:body], # is there request body
:head != env[:method], # is there response body
env[:method] != :head, # is there response body
env[:url].request_uri, # request uri path
env[:request_headers] # request headers

Expand Down Expand Up @@ -103,7 +103,7 @@ def perform_request(http, env)
end

def perform_request_with_wrapped_block(http, env, &block)
if (:get == env[:method]) && !env[:body]
if (env[:method] == :get) && !env[:body]
# prefer `get` to `request` because the former handles gzip (ruby 1.9)
request_via_get_method(http, env, &block)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/net_http_persistent.rb
Expand Up @@ -10,7 +10,7 @@ class NetHttpPersistent < NetHttp

def net_http_connection(env)
@cached_connection ||=
if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == %i[key name]
options = { name: 'Faraday' }
options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
Net::HTTP::Persistent.new(options)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/test.rb
Expand Up @@ -202,7 +202,7 @@ def call(env)
env[:params] = (query = env[:url].query) ?
params_encoder.decode(query) : {}
block_arity = stub.block.arity
status, headers, body = (block_arity >= 0) ?
status, headers, body = block_arity >= 0 ?
stub.block.call(*[env, meta].take(block_arity)) :
stub.block.call(env, meta)
save_response(env, status, body, headers)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/connection.rb
Expand Up @@ -14,7 +14,7 @@ module Faraday
#
class Connection
# A Set of allowed HTTP verbs.
METHODS = Set.new [:get, :post, :put, :delete, :head, :patch, :options, :trace, :connect]
METHODS = Set.new %i[get post put delete head patch options trace connect]

# @return [Hash] URI query unencoded key/value pairs.
attr_reader :params
Expand Down
4 changes: 2 additions & 2 deletions lib/faraday/options.rb
Expand Up @@ -52,7 +52,7 @@ def merge!(other)
other.each do |key, other_value|
self_value = send(key)
sub_options = self.class.options_for(key)
new_value = (self_value && sub_options && other_value) ? self_value.merge(other_value) : other_value
new_value = self_value && sub_options && other_value ? self_value.merge(other_value) : other_value
send("#{key}=", new_value) unless new_value.nil?
end
self
Expand Down Expand Up @@ -188,7 +188,7 @@ def [](key)
end

def symbolized_key_set
@symbolized_key_set ||= Set.new(keys.map { |k| k.to_sym })
@symbolized_key_set ||= Set.new(keys.map(&:to_sym))
end

def self.inherited(subclass)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/request/retry.rb
Expand Up @@ -23,7 +23,7 @@ module Faraday
# interval that is random between 0.1 and 0.15.
class Request::Retry < Faraday::Middleware
DEFAULT_EXCEPTIONS = [Errno::ETIMEDOUT, 'Timeout::Error', Faraday::TimeoutError, Faraday::RetriableResponse].freeze
IDEMPOTENT_METHODS = [:delete, :get, :head, :options, :put]
IDEMPOTENT_METHODS = %i[delete get head options put]

class Options < Faraday::Options.new(:max, :interval, :max_interval, :interval_randomness,
:backoff_factor, :exceptions, :methods, :retry_if, :retry_block,
Expand Down
8 changes: 4 additions & 4 deletions lib/faraday/upload_io.rb
Expand Up @@ -14,7 +14,7 @@ module Faraday
class CompositeReadIO
def initialize(*parts)
@parts = parts.flatten
@ios = @parts.map { |part| part.to_io }
@ios = @parts.map(&:to_io)
@index = 0
end

Expand All @@ -27,7 +27,7 @@ def length
#
# @return [void]
def rewind
@ios.each { |io| io.rewind }
@ios.each(&:rewind)
@index = 0
end

Expand All @@ -49,14 +49,14 @@ def read(length = nil, outbuf = nil)
end
advance_io
end
(!got_result && length) ? nil : outbuf
!got_result && length ? nil : outbuf
end

# Close each of the IOs.
#
# @return [void]
def close
@ios.each { |io| io.close }
@ios.each(&:close)
end

def ensure_open_and_readable
Expand Down
6 changes: 2 additions & 4 deletions lib/faraday/utils/headers.rb
Expand Up @@ -42,7 +42,7 @@ def initialize_copy(other)
key
else
key.to_s.split('_') # user_agent: %w(user agent)
.each { |w| w.capitalize! } # => %w(User Agent)
.each(&:capitalize!) # => %w(User Agent)
.join('-') # => "User-Agent"
end
keymap_mutex.synchronize { map[key] = value }
Expand Down Expand Up @@ -125,9 +125,7 @@ def parse(header_string)

protected

def names
@names
end
attr_reader :names

private

Expand Down
2 changes: 1 addition & 1 deletion script/proxy-server
Expand Up @@ -28,7 +28,7 @@ webrick_opts = {
ProxyAuthProc: lambda { |req, res|
if username
type, credentials = req.header['proxy-authorization'].first.to_s.split(/\s+/, 2)
unless 'Basic' == type && match_credentials.call(credentials)
unless type == 'Basic' && match_credentials.call(credentials)
res['proxy-authenticate'] = %{Basic realm="testing"}
raise WEBrick::HTTPStatus::ProxyAuthenticationRequired
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/helper_methods.rb
Expand Up @@ -93,7 +93,7 @@ def method_with_body?(method)

def big_string
kb = 1024
(32..126).map { |i| i.chr }.cycle.take(50 * kb).join
(32..126).map(&:chr).cycle.take(50 * kb).join
end
end
end
4 changes: 2 additions & 2 deletions test/helper.rb
Expand Up @@ -59,11 +59,11 @@ def capture_warnings
end

def self.jruby?
defined? RUBY_ENGINE && ('jruby' == RUBY_ENGINE)
defined? RUBY_ENGINE && (RUBY_ENGINE == 'jruby')
end

def self.rbx?
defined? RUBY_ENGINE && ('rbx' == RUBY_ENGINE)
defined? RUBY_ENGINE && (RUBY_ENGINE == 'rbx')
end

def self.ruby_22_plus?
Expand Down
6 changes: 3 additions & 3 deletions test/live_server.rb
Expand Up @@ -9,7 +9,7 @@ class LiveServer < Sinatra::Base
disable :logging
disable :protection

[:get, :post, :put, :patch, :delete, :options].each do |method|
%i[get post put patch delete options].each do |method|
send(method, '/echo') do
kind = request.request_method.downcase
out = kind.dup
Expand All @@ -21,7 +21,7 @@ class LiveServer < Sinatra::Base
end
end

[:get, :post].each do |method|
%i[get post].each do |method|
send(method, '/stream') do
content_type :txt
stream do |out|
Expand All @@ -32,7 +32,7 @@ class LiveServer < Sinatra::Base
end
end

[:get, :post].each do |method|
%i[get post].each do |method|
send(method, '/empty_stream') do
content_type :txt
stream do |out|
Expand Down
2 changes: 1 addition & 1 deletion test/shared.rb
Expand Up @@ -4,7 +4,7 @@ module Faraday
module Shared
def self.big_string
kb = 1024
(32..126).map { |i| i.chr }.cycle.take(50 * kb).join
(32..126).map(&:chr).cycle.take(50 * kb).join
end

def big_string
Expand Down