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 linting #860

Merged
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
43 changes: 1 addition & 42 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-02-20 22:19:54 +0100 using RuboCop version 0.65.0.
# on 2019-02-20 22:39:41 +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 @@ -82,41 +82,6 @@ Layout/ElseAlignment:
- 'lib/faraday/options.rb'
- 'lib/faraday/utils.rb'

# Offense count: 19
# Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/faraday/adapter/httpclient.rb'
- 'lib/faraday/adapter/net_http.rb'
- 'lib/faraday/adapter/test.rb'
- 'lib/faraday/connection.rb'
- 'lib/faraday/dependency_loader.rb'
- 'lib/faraday/encoders/flat_params_encoder.rb'
- 'lib/faraday/encoders/nested_params_encoder.rb'
- 'lib/faraday/options.rb'
- 'lib/faraday/options/env.rb'
- 'lib/faraday/rack_builder.rb'
- 'lib/faraday/request/retry.rb'
- 'lib/faraday/response.rb'
- 'spec/support/shared_examples/adapter.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Layout/EmptyLineBetweenDefs:
Exclude:
- 'lib/faraday/rack_builder.rb'
- 'spec/support/fake_safe_buffer.rb'

# Offense count: 4
# Cop supports --auto-correct.
Layout/EmptyLines:
Exclude:
- 'lib/faraday/adapter/em_synchrony/parallel_manager.rb'
- 'script/generate_certs'
- 'spec/faraday/options/options_spec.rb'
- 'spec/support/shared_examples/request_method.rb'

# Offense count: 1
# Cop supports --auto-correct.
Layout/EmptyLinesAroundAccessModifier:
Expand Down Expand Up @@ -185,12 +150,6 @@ Layout/IndentationWidth:
- 'lib/faraday/utils.rb'
- 'test/live_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
Layout/LeadingCommentSpace:
Exclude:
- 'test/adapters/em_synchrony_test.rb'

# Offense count: 2
# Cop supports --auto-correct.
Layout/MultilineBlockLayout:
Expand Down
1 change: 0 additions & 1 deletion lib/faraday/adapter/em_synchrony/parallel_manager.rb
Expand Up @@ -35,7 +35,6 @@ def run
result
end


private

# The request queue.
Expand Down
1 change: 1 addition & 0 deletions lib/faraday/adapter/httpclient.rb
Expand Up @@ -117,6 +117,7 @@ def configure_client
# @return [OpenSSL::X509::Store]
def ssl_cert_store(ssl)
return ssl[:cert_store] if ssl[:cert_store]

# Memoize the cert store so that the same one is passed to
# HTTPClient each time, to avoid resyncing SSL sesions when
# it's changed
Expand Down
1 change: 1 addition & 0 deletions lib/faraday/adapter/net_http.rb
Expand Up @@ -167,6 +167,7 @@ def configure_request(http, req)
def ssl_cert_store(ssl)
return ssl[:cert_store] if ssl[:cert_store]
return @cert_store if @cert_store

# Use the default cert store by default, i.e. system ca certs
@cert_store = OpenSSL::X509::Store.new
@cert_store.set_default_paths
Expand Down
1 change: 1 addition & 0 deletions lib/faraday/adapter/test.rb
Expand Up @@ -55,6 +55,7 @@ def empty?

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

stack = @stack[request_method]
consumed = (@consumed[request_method] ||= [])

Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/connection.rb
Expand Up @@ -503,6 +503,7 @@ def set_authorization_header(header_type, *args)

def proxy_from_env(url)
return if Faraday.ignore_env_proxy

uri = nil
if URI.parse('').respond_to?(:find_proxy)
case url
Expand Down Expand Up @@ -531,6 +532,7 @@ def find_default_proxy

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

if url && Utils.URI(url).absolute?
proxy_from_env(url)
else
Expand Down
1 change: 1 addition & 0 deletions lib/faraday/dependency_loader.rb
Expand Up @@ -12,6 +12,7 @@ def dependency(lib = nil)

def new(*)
raise "missing dependency for #{self}: #{load_error.message}" unless loaded?

super
end

Expand Down
1 change: 1 addition & 0 deletions lib/faraday/encoders/flat_params_encoder.rb
Expand Up @@ -46,6 +46,7 @@ def self.encode(params)
def self.decode(query)
empty_accumulator = {}
return nil if query == nil

split_query = (query.split('&').map do |pair|
pair.split('=', 2) if pair && !pair.empty?
end).compact
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/encoders/nested_params_encoder.rb
Expand Up @@ -48,6 +48,7 @@ def self.encode(params)
elsif value.is_a?(Array)
new_parent = "#{parent}%5B%5D"
return new_parent if value.empty?

buffer = ""
value.each_with_index do |val, i|
buffer << "#{to_query.call(new_parent, val)}&"
Expand Down Expand Up @@ -81,6 +82,7 @@ def self.decode(query)
params = {}
query.split("&").each do |pair|
next if pair.empty?

key, value = pair.split("=", 2)
key = unescape(key)
value = unescape(value.gsub(/\+/, ' ')) if value
Expand Down
3 changes: 3 additions & 0 deletions lib/faraday/options.rb
Expand Up @@ -10,6 +10,7 @@ def self.from(value)
# Public
def each
return to_enum(:each) unless block_given?

members.each do |key|
yield(key.to_sym, send(key))
end
Expand Down Expand Up @@ -98,6 +99,7 @@ def empty?
# Public
def each_key
return to_enum(:each_key) unless block_given?

keys.each do |key|
yield(key)
end
Expand All @@ -113,6 +115,7 @@ def key?(key)
# Public
def each_value
return to_enum(:each_value) unless block_given?

values.each do |value|
yield(value)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/options/env.rb
Expand Up @@ -77,6 +77,7 @@ def self.from(value)
# @param key [Object]
def [](key)
return self[current_body] if key == :body

if in_member_set?(key)
super(key)
else
Expand All @@ -88,6 +89,7 @@ def [](key)
# @param value [Object]
def []=(key, value)
return super(current_body, value) if key == :body

if in_member_set?(key)
super(key, value)
else
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/rack_builder.rb
Expand Up @@ -35,6 +35,7 @@ def initialize(klass, *args, &block)
end

def klass() @@constants[@name] end

def inspect() @name end

def ==(other)
Expand Down Expand Up @@ -226,6 +227,7 @@ def use_symbol(mod, key, *args, &block)
def assert_index(index)
idx = index.is_a?(Integer) ? index : @handlers.index(index)
raise "No such handler: #{index.inspect}" unless idx

idx
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/faraday/request/retry.rb
Expand Up @@ -175,6 +175,7 @@ def retry_request?(env, exception)

def rewind_files(body)
return unless body.is_a?(Hash)

body.each do |_, value|
if value.is_a? UploadIO
value.rewind
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/response.rb
Expand Up @@ -63,6 +63,7 @@ def on_complete

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
Expand Down Expand Up @@ -92,6 +93,7 @@ def marshal_load(env)
# Useful for applying request params after restoring a marshalled Response.
def apply_request(request_env)
raise "response didn't finish yet" unless finished?

@env = Env.from(request_env).update(@env)
return self
end
Expand Down
1 change: 0 additions & 1 deletion script/generate_certs
Expand Up @@ -30,7 +30,6 @@ def write(file, contents, env_var)
puts %(export #{env_var}="#{file}") if $shell
end


# One cert / CA for ease of testing when ignoring verification
cert, key = create_self_signed_cert(1024, [['CN', 'localhost']], 'Faraday Test CA')
write 'tmp/faraday-cert.key', key, 'SSL_KEY'
Expand Down
1 change: 0 additions & 1 deletion spec/faraday/options/options_spec.rb
Expand Up @@ -112,7 +112,6 @@ class ParentOptions < Faraday::Options.new(:a, :b, :c)
end
end


describe '#empty?' do
it 'returns true only if all options are nil' do
options = SubOptions.new
Expand Down
1 change: 1 addition & 0 deletions spec/support/fake_safe_buffer.rb
@@ -1,6 +1,7 @@
# emulates ActiveSupport::SafeBuffer#gsub
FakeSafeBuffer = Struct.new(:string) do
def to_s; self end

def gsub(regex)
string.gsub(regex) {
match, = $&, '' =~ /a/
Expand Down
1 change: 1 addition & 0 deletions spec/support/shared_examples/adapter.rb
Expand Up @@ -21,6 +21,7 @@

let(:adapter_options) do
return [] unless options[:adapter_options]

if options[:adapter_options].is_a?(Array)
options[:adapter_options]
else
Expand Down
1 change: 0 additions & 1 deletion spec/support/shared_examples/request_method.rb
Expand Up @@ -126,7 +126,6 @@
context 'when response contains big data' do
before { request_stub.to_return(body: big_string) }


it 'handles streaming' do
response = conn.public_send(http_method, '/') do |req|
req.options.on_data = Proc.new { |*args| streamed << args }
Expand Down
2 changes: 1 addition & 1 deletion test/adapters/em_synchrony_test.rb
Expand Up @@ -13,7 +13,7 @@ def adapter() :em_synchrony end
def test_binds_local_socket
host = '1.2.3.4'
conn = create_connection :request => { :bind => { :host => host } }
#put conn.get('/who-am-i').body
# put conn.get('/who-am-i').body
assert_equal host, conn.options[:bind][:host]
end
end
Expand Down