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 lint Style/N* #921

Merged
merged 4 commits into from
Mar 3, 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
57 changes: 24 additions & 33 deletions .rubocop_todo.yml
Expand Up @@ -8,7 +8,7 @@

# Offense count: 40
Metrics/AbcSize:
Max: 86
Max: 79

# Offense count: 2
# Configuration parameters: CountComments, ExcludedMethods.
Expand All @@ -21,9 +21,9 @@ Metrics/BlockLength:
Metrics/ClassLength:
Max: 216

# Offense count: 19
# Offense count: 18
Metrics/CyclomaticComplexity:
Max: 20
Max: 16

# Offense count: 45
# Configuration parameters: CountComments, ExcludedMethods.
Expand All @@ -35,9 +35,9 @@ Metrics/MethodLength:
Metrics/ModuleLength:
Max: 101

# Offense count: 17
# Offense count: 16
Metrics/PerceivedComplexity:
Max: 21
Max: 18

# Offense count: 3
Style/ClassVars:
Expand Down Expand Up @@ -82,14 +82,13 @@ Style/GlobalVars:
Exclude:
- 'script/generate_certs'

# Offense count: 27
# Offense count: 26
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/faraday/adapter/em_http.rb'
- 'lib/faraday/adapter/em_http_ssl_patch.rb'
- 'lib/faraday/adapter/em_synchrony.rb'
- 'lib/faraday/adapter/excon.rb'
- 'lib/faraday/adapter/httpclient.rb'
- 'lib/faraday/adapter/net_http.rb'
- 'lib/faraday/adapter/net_http_persistent.rb'
Expand All @@ -99,10 +98,25 @@ Style/GuardClause:
- 'lib/faraday/request/url_encoded.rb'
- 'lib/faraday/utils/headers.rb'

# Offense count: 24
# Offense count: 23
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Enabled: false
Exclude:
- 'lib/faraday.rb'
- 'lib/faraday/adapter/em_http.rb'
- 'lib/faraday/adapter/httpclient.rb'
- 'lib/faraday/adapter/net_http_persistent.rb'
- 'lib/faraday/autoload.rb'
- 'lib/faraday/connection.rb'
- 'lib/faraday/encoders/flat_params_encoder.rb'
- 'lib/faraday/encoders/nested_params_encoder.rb'
- 'lib/faraday/error.rb'
- 'lib/faraday/options/env.rb'
- 'lib/faraday/rack_builder.rb'
- 'lib/faraday/request/authorization.rb'
- 'lib/faraday/request/retry.rb'
- 'lib/faraday/utils/params_hash.rb'
- 'test/live_server.rb'

# Offense count: 1
Style/MethodMissingSuper:
Expand Down Expand Up @@ -152,30 +166,7 @@ Style/MutableConstant:
- 'lib/faraday/response/raise_error.rb'
- 'lib/faraday/utils.rb'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: predicate, comparison
Style/NilComparison:
Exclude:
- 'lib/faraday/encoders/flat_params_encoder.rb'
- 'lib/faraday/encoders/nested_params_encoder.rb'

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/faraday/adapter/em_http.rb'
- 'lib/faraday/adapter/net_http.rb'
- 'lib/faraday/encoders/nested_params_encoder.rb'
- 'lib/faraday/request/retry.rb'
- 'lib/faraday/upload_io.rb'
- 'lib/faraday/utils/headers.rb'

# Offense count: 278
# Offense count: 275
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/em_http.rb
Expand Up @@ -220,7 +220,7 @@ def add
end

def run
if @num_registered > 0
if @num_registered.positive?
@running = true
EventMachine.run do
@registered_procs.each do |proc|
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/net_http.rb
Expand Up @@ -87,7 +87,7 @@ def perform_request(http, env)
size = 0
yielded = false
http_response = perform_request_with_wrapped_block(http, env) do |chunk|
if chunk.bytesize > 0 || size > 0
if chunk.bytesize.positive? || size.positive?
yielded = true
size += chunk.bytesize
env[:request].on_data.call(chunk, size)
Expand Down
7 changes: 4 additions & 3 deletions lib/faraday/encoders/flat_params_encoder.rb
Expand Up @@ -8,7 +8,7 @@ class << self
end

def self.encode(params)
return nil if params == nil
return nil if params.nil?

unless params.is_a?(Array)
unless params.respond_to?(:to_hash)
Expand All @@ -30,7 +30,7 @@ def self.encode(params)
params.each do |key, value|
encoded_key = escape(key)
value = value.to_s if value == true || value == false
if value == nil
if value.nil?
buffer << "#{encoded_key}&"
elsif value.is_a?(Array)
value.each do |sub_value|
Expand All @@ -46,8 +46,9 @@ def self.encode(params)
end

def self.decode(query)
return nil if query.nil?
iMacTia marked this conversation as resolved.
Show resolved Hide resolved

empty_accumulator = {}
return nil if query == nil

split_query = (query.split('&').map do |pair|
pair.split('=', 2) if pair && !pair.empty?
Expand Down
6 changes: 3 additions & 3 deletions lib/faraday/encoders/nested_params_encoder.rb
Expand Up @@ -16,7 +16,7 @@ class << self
#
# @raise [TypeError] if params can not be converted to a Hash
def self.encode(params)
return nil if params == nil
return nil if params.nil?

unless params.is_a?(Array)
unless params.respond_to?(:to_hash)
Expand Down Expand Up @@ -79,7 +79,7 @@ def self.encode(params)
#
# @raise [TypeError] if the nesting is incorrect
def self.decode(query)
return nil if query == nil
return nil if query.nil?

params = {}
query.split('&').each do |pair|
Expand Down Expand Up @@ -133,7 +133,7 @@ def self.dehash(hash, depth)
hash[key] = dehash(value, depth + 1) if value.is_a?(Hash)
end

if depth > 0 && !hash.empty? && hash.keys.all? { |k| k =~ /^\d+$/ }
if depth.positive? && !hash.empty? && hash.keys.all? { |k| k =~ /^\d+$/ }
hash.keys.sort.inject([]) { |all, key| all << hash[key] }
else
hash
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/request/retry.rb
Expand Up @@ -129,7 +129,7 @@ def call(env)
raise Faraday::RetriableResponse.new(nil, resp) if @options.retry_statuses.include?(resp.status)
end
rescue @errmatch => exception
if retries > 0 && retry_request?(env, exception)
if retries.positive? && retry_request?(env, exception)
retries -= 1
rewind_files(request_body)
@options.retry_block.call(env, @options, retries, exception)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/upload_io.rb
Expand Up @@ -42,7 +42,7 @@ def read(length = nil, outbuf = nil)
result.force_encoding('BINARY') if result.respond_to?(:force_encoding)
outbuf << result
length -= result.length if length
break if length == 0
break if length&.zero?
end
advance_io
end
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/utils/headers.rb
Expand Up @@ -117,7 +117,7 @@ def parse(header_string)
last_response = headers.slice(start_index, headers.size)

last_response
.tap { |a| a.shift if a.first.index('HTTP/') == 0 } # drop the HTTP status line
.tap { |a| a.shift if a.first.start_with?('HTTP/') } # drop the HTTP status line
.map { |h| h.split(/:\s*/, 2) } # split key and value
.reject { |p| p[0].nil? } # ignore blank lines
.each { |key, value| add_parsed(key, value) } # join multiple values with a comma
Expand Down