Skip to content

Commit

Permalink
Merge pull request #874 from lostisland/rubocop-Lint-AssignmentInCond…
Browse files Browse the repository at this point in the history
…ition

[Rubocop] fix Lint/AssignmentInCondition
  • Loading branch information
olleolleolle committed Feb 25, 2019
2 parents 281e3f4 + 9cd764b commit 7af0218
Show file tree
Hide file tree
Showing 43 changed files with 127 additions and 155 deletions.
44 changes: 8 additions & 36 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-02-24 10:08:41 +0100 using RuboCop version 0.65.0.
# on 2019-02-25 23:11:38 +0100 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 @@ -42,16 +42,13 @@ Layout/EmptyLinesAroundClassBody:
- 'test/adapters/em_synchrony_test.rb'
- 'test/adapters/rack_test.rb'

# Offense count: 5
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Layout/EndAlignment:
Exclude:
- 'lib/faraday/adapter/rack.rb'
- 'lib/faraday/connection.rb'
- 'lib/faraday/options.rb'
- 'lib/faraday/utils.rb'
- 'test/helper.rb'

# Offense count: 3
Expand Down Expand Up @@ -195,24 +192,6 @@ Layout/TrailingWhitespace:
Exclude:
- 'lib/faraday/adapter/test.rb'

# Offense count: 20
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'lib/faraday/adapter/em_http.rb'
- 'lib/faraday/adapter/excon.rb'
- 'lib/faraday/adapter/httpclient.rb'
- 'lib/faraday/adapter/net_http.rb'
- 'lib/faraday/adapter/patron.rb'
- 'lib/faraday/middleware_registry.rb'
- 'lib/faraday/options.rb'
- 'lib/faraday/options/env.rb'
- 'lib/faraday/options/proxy_options.rb'
- 'lib/faraday/request.rb'
- 'lib/faraday/upload_io.rb'
- 'script/proxy-server'
- 'script/server'

# Offense count: 1
Lint/HandleExceptions:
Exclude:
Expand Down Expand Up @@ -277,12 +256,12 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 489
Max: 473

# Offense count: 5
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 217
Max: 216

# Offense count: 20
Metrics/CyclomaticComplexity:
Expand Down Expand Up @@ -598,7 +577,7 @@ Style/GuardClause:
- 'lib/faraday/request/url_encoded.rb'
- 'lib/faraday/utils/headers.rb'

# Offense count: 163
# Offense count: 161
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Expand Down Expand Up @@ -667,7 +646,7 @@ Style/MultipleComparison:
Exclude:
- 'lib/faraday/encoders/flat_params_encoder.rb'

# Offense count: 12
# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Expand Down Expand Up @@ -922,13 +901,6 @@ Style/StderrPuts:
Exclude:
- 'lib/faraday/upload_io.rb'

# Offense count: 130
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand All @@ -945,7 +917,7 @@ Style/StructInheritance:
- 'lib/faraday/request.rb'
- 'spec/faraday/rack_builder_spec.rb'

# Offense count: 9
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: MinSize.
# SupportedStyles: percent, brackets
Expand Down Expand Up @@ -1009,7 +981,7 @@ Style/YodaCondition:
- 'script/proxy-server'
- 'test/helper.rb'

# Offense count: 267
# Offense count: 283
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ RSpec::Core::RakeTask.new(:spec)

task :default => :test

desc "Run all tests"
desc 'Run all tests'
task :test => [:spec]
6 changes: 3 additions & 3 deletions faraday.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

lib = "faraday"
lib = 'faraday'
lib_file = File.expand_path("../lib/#{lib}.rb", __FILE__)
File.read(lib_file) =~ /\bVERSION\s*=\s*["'](.+?)["']/
version = $1
Expand All @@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
spec.name = lib
spec.version = version

spec.summary = "HTTP/REST API client library."
spec.summary = 'HTTP/REST API client library.'

spec.authors = ["Rick Olson"]
spec.authors = ['Rick Olson']
spec.email = 'technoweenie@gmail.com'
spec.homepage = 'https://github.com/lostisland/faraday'
spec.licenses = ['MIT']
Expand Down
12 changes: 6 additions & 6 deletions lib/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# conn.get '/'
#
module Faraday
VERSION = "0.15.3"
VERSION = '0.15.3'
METHODS_WITH_QUERY = %w[get head delete connect trace]
METHODS_WITH_BODY = %w[post put patch]

Expand Down Expand Up @@ -116,8 +116,8 @@ def method_missing(name, *args, &block)
end

self.ignore_env_proxy = false
self.root_path = File.expand_path "..", __FILE__
self.lib_path = File.expand_path "../faraday", __FILE__
self.root_path = File.expand_path '..', __FILE__
self.lib_path = File.expand_path '../faraday', __FILE__
self.default_adapter = :net_http

# @overload default_connection
Expand Down Expand Up @@ -151,10 +151,10 @@ def self.default_connection_options=(options)
Timer = Timeout
end

require_libs "utils", "options", "connection", "rack_builder", "parameters",
"middleware", "adapter", "request", "response", "upload_io", "error"
require_libs 'utils', 'options', 'connection', 'rack_builder', 'parameters',
'middleware', 'adapter', 'request', 'response', 'upload_io', 'error'

if !ENV["FARADAY_NO_AUTOLOAD"]
if !ENV['FARADAY_NO_AUTOLOAD']
require_lib 'autoload'
end
end
18 changes: 9 additions & 9 deletions lib/faraday/adapter/em_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def read_body(env)

# Reads out proxy settings from env into options
def configure_proxy(options, env)
if proxy = request_options(env)[:proxy]
if (proxy = request_options(env)[:proxy])
options[:proxy] = {
:host => proxy[:uri].host,
:port => proxy[:uri].port,
Expand All @@ -46,7 +46,7 @@ def configure_proxy(options, env)

# Reads out host and port settings from env into options
def configure_socket(options, env)
if bind = request_options(env)[:bind]
if (bind = request_options(env)[:bind])
options[:bind] = {
:host => bind[:host],
:port => bind[:port]
Expand Down Expand Up @@ -132,7 +132,7 @@ def perform_request(env)
end
end
rescue EventMachine::Connectify::CONNECTError => err
if err.message.include?("Proxy Authentication Required")
if err.message.include?('Proxy Authentication Required')
raise Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
else
raise Faraday::ConnectionFailed, err
Expand Down Expand Up @@ -168,18 +168,18 @@ def create_request(env)
end

def error_message(client)
client.error or "request failed"
client.error or 'request failed'
end

def raise_error(msg)
errklass = Faraday::ClientError
if msg == Errno::ETIMEDOUT
errklass = Faraday::TimeoutError
msg = "request timed out"
msg = 'request timed out'
elsif msg == Errno::ECONNREFUSED
errklass = Faraday::ConnectionFailed
msg = "connection refused"
elsif msg == "connection closed by server"
msg = 'connection refused'
elsif msg == 'connection closed by server'
errklass = Faraday::ConnectionFailed
end
raise errklass, msg
Expand Down Expand Up @@ -228,7 +228,7 @@ def run
end
end
if !@errors.empty?
raise Faraday::ClientError, @errors.first || "connection failed"
raise Faraday::ClientError, @errors.first || 'connection failed'
end
end
ensure
Expand All @@ -254,7 +254,7 @@ def check_finished
begin
require 'openssl'
rescue LoadError
warn "Warning: no such file to load -- openssl. Make sure it is installed if you want HTTPS support"
warn 'Warning: no such file to load -- openssl. Make sure it is installed if you want HTTPS support'
else
require 'faraday/adapter/em_http_ssl_patch'
end if Faraday::Adapter::EMHttp.loaded?
6 changes: 3 additions & 3 deletions lib/faraday/adapter/em_synchrony.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ def call(env)
rescue Errno::ECONNREFUSED
raise Faraday::ConnectionFailed, $!
rescue EventMachine::Connectify::CONNECTError => err
if err.message.include?("Proxy Authentication Required")
if err.message.include?('Proxy Authentication Required')
raise Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
else
raise Faraday::ConnectionFailed, err
end
rescue Errno::ETIMEDOUT => err
raise Faraday::TimeoutError, err
rescue RuntimeError => err
if err.message == "connection closed by server"
if err.message == 'connection closed by server'
raise Faraday::ConnectionFailed, err
else
raise
Expand All @@ -113,7 +113,7 @@ def create_request(env)
begin
require 'openssl'
rescue LoadError
warn "Warning: no such file to load -- openssl. Make sure it is installed if you want HTTPS support"
warn 'Warning: no such file to load -- openssl. Make sure it is installed if you want HTTPS support'
else
require 'faraday/adapter/em_http_ssl_patch'
end if Faraday::Adapter::EMSynchrony.loaded?
2 changes: 1 addition & 1 deletion lib/faraday/adapter/excon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def call(env)
super

opts = {}
if env[:url].scheme == 'https' && ssl = env[:ssl]
if env[:url].scheme == 'https' && (ssl = env[:ssl])
opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true)
opts[:ssl_ca_path] = ssl[:ca_path] if ssl[:ca_path]
opts[:ssl_ca_file] = ssl[:ca_file] if ssl[:ca_file]
Expand Down
8 changes: 4 additions & 4 deletions lib/faraday/adapter/httpclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ def call(env)
# enable compression
client.transparent_gzip_decompression = true

if req = env[:request]
if proxy = req[:proxy]
if (req = env[:request])
if (proxy = req[:proxy])
configure_proxy proxy
end

if bind = req[:bind]
if (bind = req[:bind])
configure_socket bind
end

configure_timeouts req
end

if env[:url].scheme == 'https' && ssl = env[:ssl]
if env[:url].scheme == 'https' && (ssl = env[:ssl])
configure_ssl ssl
end

Expand Down
6 changes: 3 additions & 3 deletions lib/faraday/adapter/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
begin
require 'net/https'
rescue LoadError
warn "Warning: no such file to load -- net/https. Make sure openssl is installed if you want ssl support"
warn 'Warning: no such file to load -- net/https. Make sure openssl is installed if you want ssl support'
require 'net/http'
end
require 'zlib'
Expand Down Expand Up @@ -93,7 +93,7 @@ def perform_request(http, env)
env[:request].on_data.call(chunk, size)
end
end
env[:request].on_data.call("", 0) unless yielded
env[:request].on_data.call('', 0) unless yielded
# Net::HTTP returns something, but it's not meaningful according to the docs.
http_response.body = nil
http_response
Expand Down Expand Up @@ -130,7 +130,7 @@ def with_net_http_connection(env)
end

def net_http_connection(env)
if proxy = env[:request][:proxy]
if (proxy = env[:request][:proxy])
Net::HTTP::Proxy(proxy[:uri].hostname, proxy[:uri].port, proxy[:user], proxy[:password])
else
Net::HTTP
Expand Down
26 changes: 13 additions & 13 deletions lib/faraday/adapter/patron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def call(env)
@config_block.call(session) if @config_block
configure_ssl(session, env[:ssl]) if env[:url].scheme == 'https' and env[:ssl]

if req = env[:request]
if (req = env[:request])
session.timeout = session.connect_timeout = req[:timeout] if req[:timeout]
session.connect_timeout = req[:open_timeout] if req[:open_timeout]

if proxy = req[:proxy]
if (proxy = req[:proxy])
proxy_uri = proxy[:uri].dup
proxy_uri.user = proxy[:user] && Utils.escape(proxy[:user]).gsub('+', '%20')
proxy_uri.password = proxy[:password] && Utils.escape(proxy[:password]).gsub('+', '%20')
Expand Down Expand Up @@ -51,7 +51,7 @@ def call(env)
raise Faraday::TimeoutError, err
end
rescue ::Patron::Error => err
if err.message.include?("code 407")
if err.message.include?('code 407')
raise Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
else
raise Faraday::ConnectionFailed, err
Expand All @@ -67,8 +67,8 @@ def call(env)
actions << :options unless actions.include? :options
else
# Patron 0.4.20 and up
actions << "PATCH" unless actions.include? "PATCH"
actions << "OPTIONS" unless actions.include? "OPTIONS"
actions << 'PATCH' unless actions.include? 'PATCH'
actions << 'OPTIONS' unless actions.include? 'OPTIONS'
end
end
end
Expand All @@ -84,14 +84,14 @@ def configure_ssl(session, ssl)
private

CURL_TIMEOUT_MESSAGES = [
"Connection time-out",
"Connection timed out",
"Timed out before name resolve",
"server connect has timed out",
"Resolving timed out",
"name lookup timed out",
"timed out before SSL",
"connect() timed out"
'Connection time-out',
'Connection timed out',
'Timed out before name resolve',
'server connect has timed out',
'Resolving timed out',
'name lookup timed out',
'timed out before SSL',
'connect() timed out'
].freeze

def connection_timed_out_message?(message)
Expand Down
Loading

0 comments on commit 7af0218

Please sign in to comment.