Skip to content

Commit

Permalink
chore: RuboCop linting (#860)
Browse files Browse the repository at this point in the history
* chore: RuboCop lint Layout/LeadingCommentSpace

* chore: RuboCop lint Layout/EmptyLineAfterGuardClause

* chore: RuboCop lint Layout/EmptyLineBetweenDefs

* chore: RuboCop lint Layout/EmptyLines

* chore: Regenerate RuboCop TODO
  • Loading branch information
olleolleolle committed Feb 20, 2019
1 parent f98c3e9 commit b2857e6
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 47 deletions.
43 changes: 1 addition & 42 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-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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit b2857e6

Please sign in to comment.