Skip to content

Commit

Permalink
Merge pull request #895 from olleolleolle/fix/redundant-cops
Browse files Browse the repository at this point in the history
chore: RuboCop lint Style/Redundant* cops
  • Loading branch information
technoweenie committed Feb 27, 2019
2 parents 94f4175 + afd5e63 commit 5adaaab
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 70 deletions.
41 changes: 2 additions & 39 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-02-27 21:25:04 +0100 using RuboCop version 0.65.0.
# on 2019-02-27 21:48: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 @@ -450,15 +450,14 @@ Style/MutableConstant:
- 'lib/faraday/response/raise_error.rb'
- 'lib/faraday/utils.rb'

# Offense count: 9
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: both, prefix, postfix
Style/NegatedIf:
Exclude:
- 'lib/faraday.rb'
- 'lib/faraday/adapter/em_http.rb'
- 'lib/faraday/adapter/test.rb'
- 'lib/faraday/connection.rb'
- 'lib/faraday/encoders/flat_params_encoder.rb'
- 'lib/faraday/encoders/nested_params_encoder.rb'
Expand Down Expand Up @@ -583,42 +582,6 @@ Style/RaiseArgs:
- 'lib/faraday/middleware_registry.rb'
- 'test/adapters/integration.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantException:
Exclude:
- 'spec/faraday/adapter/patron_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantParentheses:
Exclude:
- 'lib/faraday/rack_builder.rb'

# Offense count: 9
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Exclude:
- 'lib/faraday/adapter/test.rb'
- 'lib/faraday/encoders/flat_params_encoder.rb'
- 'lib/faraday/encoders/nested_params_encoder.rb'
- 'lib/faraday/request/multipart.rb'
- 'lib/faraday/response.rb'
- 'script/generate_certs'

# Offense count: 15
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- 'lib/faraday/adapter.rb'
- 'lib/faraday/connection.rb'
- 'lib/faraday/dependency_loader.rb'
- 'lib/faraday/options.rb'
- 'lib/faraday/rack_builder.rb'
- 'lib/faraday/utils/headers.rb'
- 'test/adapters/integration.rb'

# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter.rb
Expand Up @@ -28,7 +28,7 @@ def supports_parallel?() @supports_parallel end

def inherited(subclass)
super
subclass.supports_parallel = self.supports_parallel?
subclass.supports_parallel = supports_parallel?
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/faraday/adapter/test.rb
Expand Up @@ -56,7 +56,7 @@ def empty?
end

def match(request_method, host, path, headers, body)
return false if !@stack.key?(request_method)
return false unless @stack.key?(request_method)

stack = @stack[request_method]
consumed = (@consumed[request_method] ||= [])
Expand Down Expand Up @@ -149,11 +149,11 @@ def matches?(request_host, request_uri, request_headers, request_body)
# meta is a hash use as carrier
# that will be yielded to consumer block
meta = {}
return (host.nil? || host == request_host) &&
path_match?(request_path, meta) &&
params_match?(request_params) &&
(body.to_s.size.zero? || request_body == body) &&
headers_match?(request_headers), meta
[(host.nil? || host == request_host) &&
path_match?(request_path, meta) &&
params_match?(request_params) &&
(body.to_s.size.zero? || request_body == body) &&
headers_match?(request_headers), meta]
end

def path_match?(request_path, meta)
Expand Down
10 changes: 5 additions & 5 deletions lib/faraday/connection.rb
Expand Up @@ -493,9 +493,9 @@ def run_request(method, url, body, headers)
# @return [Faraday::Request]
def build_request(method)
Request.create(method) do |req|
req.params = self.params.dup
req.headers = self.headers.dup
req.options = self.options
req.params = params.dup
req.headers = headers.dup
req.options = options
yield(req) if block_given?
end
end
Expand Down Expand Up @@ -586,12 +586,12 @@ def find_default_proxy
end

def proxy_for_request(url)
return self.proxy if @manual_proxy
return proxy if @manual_proxy

if url && Utils.URI(url).absolute?
proxy_from_env(url)
else
self.proxy
proxy
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/dependency_loader.rb
Expand Up @@ -24,7 +24,7 @@ def loaded?

def inherited(subclass)
super
subclass.send(:load_error=, self.load_error)
subclass.send(:load_error=, load_error)
end
end
end
4 changes: 2 additions & 2 deletions lib/faraday/encoders/flat_params_encoder.rb
Expand Up @@ -42,7 +42,7 @@ def self.encode(params)
buffer << "#{encoded_key}=#{encoded_value}&"
end
end
return buffer.chop
buffer.chop
end

def self.decode(query)
Expand All @@ -52,7 +52,7 @@ def self.decode(query)
split_query = (query.split('&').map do |pair|
pair.split('=', 2) if pair && !pair.empty?
end).compact
return split_query.inject(empty_accumulator.dup) do |accu, pair|
split_query.inject(empty_accumulator.dup) do |accu, pair|
pair[0] = unescape(pair[0])
pair[1] = true if pair[1].nil?
if pair[1].respond_to?(:to_str)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/encoders/nested_params_encoder.rb
Expand Up @@ -70,7 +70,7 @@ def self.encode(params)
encoded_parent = escape(parent)
buffer << "#{to_query.call(encoded_parent, value)}&"
end
return buffer.chop
buffer.chop
end

# @param query [nil, String]
Expand Down
6 changes: 3 additions & 3 deletions lib/faraday/options.rb
Expand Up @@ -30,7 +30,7 @@ def update(obj)
new_value = value
end

self.send("#{key}=", new_value) unless new_value.nil?
send("#{key}=", new_value) unless new_value.nil?
end
self
end
Expand All @@ -50,10 +50,10 @@ def clear
# Public
def merge!(other)
other.each do |key, other_value|
self_value = self.send(key)
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
self.send("#{key}=", new_value) unless new_value.nil?
send("#{key}=", new_value) unless new_value.nil?
end
self
end
Expand Down
6 changes: 3 additions & 3 deletions lib/faraday/rack_builder.rb
Expand Up @@ -42,7 +42,7 @@ def inspect() @name end

def ==(other)
if other.is_a? Handler
self.name == other.name
name == other.name
elsif other.respond_to? :name
klass == other
else
Expand All @@ -62,7 +62,7 @@ def initialize(handlers = [], adapter = nil, &block)
build(&block)
elsif @handlers.empty?
# default stack, if nothing else is configured
self.request :url_encoded
request :url_encoded
self.adapter Faraday.default_adapter
end
end
Expand Down Expand Up @@ -170,7 +170,7 @@ def app
def to_app
# last added handler is the deepest and thus closest to the inner app
# adapter is always the last one
(@handlers).reverse.inject(@adapter.build) { |app, handler| handler.build(app) }
@handlers.reverse.inject(@adapter.build) { |app, handler| handler.build(app) }
end

def ==(other)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/request/multipart.rb
Expand Up @@ -54,7 +54,7 @@ def create_multipart(env, params)

body = Faraday::CompositeReadIO.new(parts)
env.request_headers[Faraday::Env::ContentLength] = body.length.to_s
return body
body
end

# @return [String]
Expand Down
6 changes: 3 additions & 3 deletions lib/faraday/response.rb
Expand Up @@ -60,15 +60,15 @@ def on_complete
else
yield(env)
end
return self
self
end

def finish(env)
raise 'response already finished' if finished?

@env = env.is_a?(Env) ? env : Env.from(env)
@on_complete_callbacks.each { |callback| callback.call(@env) }
return self
self
end

def success?
Expand Down Expand Up @@ -97,7 +97,7 @@ def apply_request(request_env)
raise "response didn't finish yet" unless finished?

@env = Env.from(request_env).update(@env)
return self
self
end
end
end
4 changes: 2 additions & 2 deletions lib/faraday/utils/headers.rb
Expand Up @@ -20,7 +20,7 @@ def self.allocate
def initialize(hash = nil)
super()
@names = {}
self.update(hash || {})
update(hash || {})
end

def initialize_names
Expand Down Expand Up @@ -99,7 +99,7 @@ def merge(other)
def replace(other)
clear
@names.clear
self.update other
update other
self
end

Expand Down
2 changes: 1 addition & 1 deletion script/generate_certs
Expand Up @@ -23,7 +23,7 @@ def create_self_signed_cert(bits, cn, comment)
cert.not_after = Time.now + (365 * 24 * 60 * 60)
cert.public_key = rsa.public_key
cert.sign(rsa, OpenSSL::Digest::SHA1.new)
return [cert, rsa]
[cert, rsa]
end

def write(file, contents, env_var)
Expand Down
2 changes: 1 addition & 1 deletion spec/faraday/adapter/patron_spec.rb
Expand Up @@ -9,7 +9,7 @@
conn = Faraday.new do |f|
f.adapter :patron do |session|
session.max_redirects = 10
raise RuntimeError, 'Configuration block called'
raise 'Configuration block called'
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/adapters/integration.rb
Expand Up @@ -16,7 +16,7 @@ def self.apply(base, *extra_features)
features = [:Common]
features.concat extra_features
features << :SSL if base.ssl_mode?
features.each { |name| base.send(:include, self.const_get(name)) }
features.each { |name| base.send(:include, const_get(name)) }
yield if block_given?
elsif !defined? @warned
warn 'Warning: Not running integration tests against a live server.'
Expand Down

0 comments on commit 5adaaab

Please sign in to comment.