From 768c5151d254c0cace0a7c274984305d177a9d4e Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Wed, 27 Feb 2019 21:42:20 +0100 Subject: [PATCH 1/5] chore: RuboCop lint Style/RedundantReturn --- lib/faraday/adapter/test.rb | 4 ++-- lib/faraday/encoders/flat_params_encoder.rb | 4 ++-- lib/faraday/encoders/nested_params_encoder.rb | 2 +- lib/faraday/request/multipart.rb | 2 +- lib/faraday/response.rb | 6 +++--- script/generate_certs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/faraday/adapter/test.rb b/lib/faraday/adapter/test.rb index e4c15bd66..a7327aeb3 100644 --- a/lib/faraday/adapter/test.rb +++ b/lib/faraday/adapter/test.rb @@ -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) && + [(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 + headers_match?(request_headers), meta] end def path_match?(request_path, meta) diff --git a/lib/faraday/encoders/flat_params_encoder.rb b/lib/faraday/encoders/flat_params_encoder.rb index 050191a1a..77709549a 100644 --- a/lib/faraday/encoders/flat_params_encoder.rb +++ b/lib/faraday/encoders/flat_params_encoder.rb @@ -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) @@ -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) diff --git a/lib/faraday/encoders/nested_params_encoder.rb b/lib/faraday/encoders/nested_params_encoder.rb index 01155c0dc..a03bdb84c 100644 --- a/lib/faraday/encoders/nested_params_encoder.rb +++ b/lib/faraday/encoders/nested_params_encoder.rb @@ -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] diff --git a/lib/faraday/request/multipart.rb b/lib/faraday/request/multipart.rb index 990617859..3b54404c0 100644 --- a/lib/faraday/request/multipart.rb +++ b/lib/faraday/request/multipart.rb @@ -55,7 +55,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] diff --git a/lib/faraday/response.rb b/lib/faraday/response.rb index 3cb5701c0..615aa3d9e 100644 --- a/lib/faraday/response.rb +++ b/lib/faraday/response.rb @@ -60,7 +60,7 @@ def on_complete else yield(env) end - return self + self end def finish(env) @@ -68,7 +68,7 @@ def finish(env) @env = env.is_a?(Env) ? env : Env.from(env) @on_complete_callbacks.each { |callback| callback.call(@env) } - return self + self end def success? @@ -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 diff --git a/script/generate_certs b/script/generate_certs index 5e1a64cec..32393fc23 100755 --- a/script/generate_certs +++ b/script/generate_certs @@ -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) From ff2a6d7eda37fa1a3e2af6faab41e5a3ef917fbc Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Wed, 27 Feb 2019 21:43:16 +0100 Subject: [PATCH 2/5] chore: RuboCop lint Style/RedundantParentheses --- lib/faraday/rack_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/faraday/rack_builder.rb b/lib/faraday/rack_builder.rb index 13d4c6475..2f7523345 100644 --- a/lib/faraday/rack_builder.rb +++ b/lib/faraday/rack_builder.rb @@ -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) From f9ffeb26f28b4b8956298de59065157dba2c1ff4 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Wed, 27 Feb 2019 21:43:58 +0100 Subject: [PATCH 3/5] chore: RuboCop lint Style/RedundantException --- spec/faraday/adapter/patron_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/faraday/adapter/patron_spec.rb b/spec/faraday/adapter/patron_spec.rb index 81de1eace..812fd1a06 100644 --- a/spec/faraday/adapter/patron_spec.rb +++ b/spec/faraday/adapter/patron_spec.rb @@ -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 From f3cf9951405f4eddca44e8df0d036072dd438e9f Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Wed, 27 Feb 2019 21:45:48 +0100 Subject: [PATCH 4/5] chore: RuboCop lint Style/RedundantSelf --- lib/faraday/adapter.rb | 2 +- lib/faraday/connection.rb | 10 +++++----- lib/faraday/dependency_loader.rb | 2 +- lib/faraday/options.rb | 6 +++--- lib/faraday/rack_builder.rb | 4 ++-- lib/faraday/utils/headers.rb | 4 ++-- test/adapters/integration.rb | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/faraday/adapter.rb b/lib/faraday/adapter.rb index 3f5f49ca7..368311535 100644 --- a/lib/faraday/adapter.rb +++ b/lib/faraday/adapter.rb @@ -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 diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index bfad355a9..99aa139c1 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -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 @@ -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 diff --git a/lib/faraday/dependency_loader.rb b/lib/faraday/dependency_loader.rb index d7637fdaf..84464bd87 100644 --- a/lib/faraday/dependency_loader.rb +++ b/lib/faraday/dependency_loader.rb @@ -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 diff --git a/lib/faraday/options.rb b/lib/faraday/options.rb index 45a4e23e0..5b87d7907 100644 --- a/lib/faraday/options.rb +++ b/lib/faraday/options.rb @@ -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 @@ -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 diff --git a/lib/faraday/rack_builder.rb b/lib/faraday/rack_builder.rb index 2f7523345..94deabf67 100644 --- a/lib/faraday/rack_builder.rb +++ b/lib/faraday/rack_builder.rb @@ -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 @@ -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 diff --git a/lib/faraday/utils/headers.rb b/lib/faraday/utils/headers.rb index 8e3342e48..192a86766 100644 --- a/lib/faraday/utils/headers.rb +++ b/lib/faraday/utils/headers.rb @@ -20,7 +20,7 @@ def self.allocate def initialize(hash = nil) super() @names = {} - self.update(hash || {}) + update(hash || {}) end def initialize_names @@ -99,7 +99,7 @@ def merge(other) def replace(other) clear @names.clear - self.update other + update other self end diff --git a/test/adapters/integration.rb b/test/adapters/integration.rb index f52ef8aba..befb10ba3 100644 --- a/test/adapters/integration.rb +++ b/test/adapters/integration.rb @@ -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.' From afd5e634cc9358000156170bf72c4e54021c8818 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Wed, 27 Feb 2019 21:46:20 +0100 Subject: [PATCH 5/5] chore: RuboCop configuration regenerated --- .rubocop_todo.yml | 41 ++----------------------------------- lib/faraday/adapter/test.rb | 10 ++++----- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f6cb01e99..1d36f6c93 100644 --- a/.rubocop_todo.yml +++ b/.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 @@ -450,7 +450,7 @@ 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 @@ -458,7 +458,6 @@ 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' @@ -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. diff --git a/lib/faraday/adapter/test.rb b/lib/faraday/adapter/test.rb index a7327aeb3..ae8f0672d 100644 --- a/lib/faraday/adapter/test.rb +++ b/lib/faraday/adapter/test.rb @@ -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] ||= []) @@ -150,10 +150,10 @@ def matches?(request_host, request_uri, request_headers, request_body) # that will be yielded to consumer block 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] + 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)