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/P* #920

Merged
merged 5 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
42 changes: 0 additions & 42 deletions .rubocop_todo.yml
Expand Up @@ -175,48 +175,6 @@ Style/NumericPredicate:
- 'lib/faraday/upload_io.rb'
- 'lib/faraday/utils/headers.rb'

# Offense count: 7
# Cop supports --auto-correct.
Style/ParallelAssignment:
Exclude:
- 'lib/faraday/rack_builder.rb'
- 'script/server'
- 'spec/support/helper_methods.rb'
- 'spec/support/shared_examples/request_method.rb'
- 'test/adapters/integration.rb'
- 'test/helper.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions.
Style/ParenthesesAroundCondition:
Exclude:
- 'lib/faraday/request/multipart.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/PerlBackrefs:
Exclude:
- 'faraday.gemspec'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: short, verbose
Style/PreferredHashMethods:
Exclude:
- 'lib/faraday/encoders/nested_params_encoder.rb'

# Offense count: 11
# Cop supports --auto-correct.
Style/Proc:
Exclude:
- 'lib/faraday/connection.rb'
- 'lib/faraday/request/retry.rb'
- 'spec/faraday/request_spec.rb'
- 'spec/support/shared_examples/request_method.rb'
- 'test/adapters/integration.rb'

# Offense count: 278
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down
2 changes: 1 addition & 1 deletion faraday.gemspec
Expand Up @@ -3,7 +3,7 @@
lib = 'faraday'
lib_file = File.expand_path("../lib/#{lib}.rb", __FILE__)
File.read(lib_file) =~ /\bVERSION\s*=\s*["'](.+?)["']/
version = $1
version = Regexp.last_match(1)

Gem::Specification.new do |spec|
spec.name = lib
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/connection.rb
Expand Up @@ -73,7 +73,7 @@ def initialize(url = nil, options = nil)

@builder = options.builder || begin
# pass an empty block to Builder so it doesn't assume default middleware
options.new_builder(block_given? ? Proc.new { |b| } : nil)
options.new_builder(block_given? ? proc { |b| } : nil)
end

self.url_prefix = url || 'http:/'
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/encoders/nested_params_encoder.rb
Expand Up @@ -106,7 +106,7 @@ def self.decode(query)
end

if context.is_a?(Array) && !is_array
if !context.last.is_a?(Hash) || context.last.has_key?(subkey)
if !context.last.is_a?(Hash) || context.last.key?(subkey)
context << {}
end
context = context.last
Expand Down
3 changes: 2 additions & 1 deletion lib/faraday/rack_builder.rb
Expand Up @@ -33,7 +33,8 @@ def initialize(klass, *args, &block)
if klass.respond_to?(:name)
@@constants_mutex.synchronize { @@constants[@name] = klass }
end
@args, @block = args, block
@args = args
@block = block
end

def klass
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/request/multipart.rb
Expand Up @@ -38,7 +38,7 @@ def process_request?(env)
def has_multipart?(obj) # rubocop:disable Naming/PredicateName
if obj.respond_to?(:each)
(obj.respond_to?(:values) ? obj.values : obj).each do |val|
return true if (val.respond_to?(:content_type) || has_multipart?(val))
return true if val.respond_to?(:content_type) || has_multipart?(val)
end
end
false
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/request/retry.rb
Expand Up @@ -73,7 +73,7 @@ def retry_if
end

def retry_block
self[:retry_block] ||= Proc.new {}
self[:retry_block] ||= proc {}
end

def retry_statuses
Expand Down
3 changes: 2 additions & 1 deletion script/server
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

old_verbose, $VERBOSE = $VERBOSE, nil
old_verbose = $VERBOSE
$VERBOSE = nil
begin
require File.expand_path('../test/live_server', __dir__)
ensure
Expand Down
12 changes: 6 additions & 6 deletions spec/faraday/request_spec.rb
Expand Up @@ -23,31 +23,31 @@
end

context 'when setting the url on setup with a URI' do
let(:block) { Proc.new { |req| req.url URI.parse('foo.json?a=1') } }
let(:block) { proc { |req| req.url URI.parse('foo.json?a=1') } }

it { expect(subject.path).to eq(URI.parse('foo.json')) }
it { expect(subject.params).to eq('a' => '1') }
it { expect(subject.to_env(conn).url.to_s).to eq('http://sushi.com/api/foo.json?a=1') }
end

context 'when setting the url on setup with a string path and params' do
let(:block) { Proc.new { |req| req.url 'foo.json', 'a' => 1 } }
let(:block) { proc { |req| req.url 'foo.json', 'a' => 1 } }

it { expect(subject.path).to eq('foo.json') }
it { expect(subject.params).to eq('a' => 1) }
it { expect(subject.to_env(conn).url.to_s).to eq('http://sushi.com/api/foo.json?a=1') }
end

context 'when setting the url on setup with a path including params' do
let(:block) { Proc.new { |req| req.url 'foo.json?b=2&a=1#qqq' } }
let(:block) { proc { |req| req.url 'foo.json?b=2&a=1#qqq' } }

it { expect(subject.path).to eq('foo.json') }
it { expect(subject.params).to eq('a' => '1', 'b' => '2') }
it { expect(subject.to_env(conn).url.to_s).to eq('http://sushi.com/api/foo.json?a=1&b=2') }
end

context 'when setting a header on setup with []= syntax' do
let(:block) { Proc.new { |req| req['Server'] = 'Faraday' } }
let(:block) { proc { |req| req['Server'] = 'Faraday' } }
let(:headers) { subject.to_env(conn).request_headers }

it { expect(subject.headers['Server']).to eq('Faraday') }
Expand All @@ -56,7 +56,7 @@
end

context 'when setting the body on setup' do
let(:block) { Proc.new { |req| req.body = 'hi' } }
let(:block) { proc { |req| req.body = 'hi' } }

it { expect(subject.body).to eq('hi') }
it { expect(subject.to_env(conn).body).to eq('hi') }
Expand All @@ -79,7 +79,7 @@

context 'and per-request options set' do
let(:block) do
Proc.new do |req|
proc do |req|
req.options.timeout = 10
req.options.boundary = 'boo'
req.options.oauth[:consumer_secret] = 'xyz'
Expand Down
3 changes: 2 additions & 1 deletion spec/support/helper_methods.rb
Expand Up @@ -74,7 +74,8 @@ def with_env_proxy_disabled
end

def capture_warnings
old, $stderr = $stderr, StringIO.new
old = $stderr
$stderr = StringIO.new
begin
yield
$stderr.string
Expand Down
7 changes: 4 additions & 3 deletions spec/support/shared_examples/request_method.rb
Expand Up @@ -137,7 +137,7 @@
context 'when response is empty' do
it do
conn.public_send(http_method, '/') do |req|
req.options.on_data = Proc.new { |*args| streamed << args }
req.options.on_data = proc { |*args| streamed << args }
end

expect(streamed).to eq([['', 0]])
Expand All @@ -149,7 +149,7 @@

it 'handles streaming' do
response = conn.public_send(http_method, '/') do |req|
req.options.on_data = Proc.new { |*args| streamed << args }
req.options.on_data = proc { |*args| streamed << args }
end

expect(response.body).to eq('')
Expand All @@ -161,7 +161,8 @@

on_feature :parallel do
it 'handles parallel requests' do
resp1, resp2 = nil, nil
resp1 = nil
resp2 = nil
payload1 = { a: '1' }
payload2 = { b: '2' }
request_stub.with(Hash[query_or_body, payload1])
Expand Down
8 changes: 5 additions & 3 deletions test/adapters/integration.rb
Expand Up @@ -44,8 +44,10 @@ def test_no_parallel_support

module ParallelNonStreaming
def test_callback_is_called_in_parallel_with_no_streaming_support
resp1, resp2 = nil, nil
streamed1, streamed2 = nil, nil
resp1 = nil
resp2 = nil
streamed1 = nil
streamed2 = nil

connection = create_connection
err = capture_warnings do
Expand Down Expand Up @@ -121,7 +123,7 @@ def create_connection(options = {}, &optional_connection_config_blk)
builder_block = if adapter == :default
nil
else
Proc.new do |b|
proc do |b|
b.request :multipart
b.request :url_encoded
b.adapter adapter, *adapter_options, &optional_connection_config_blk
Expand Down
3 changes: 2 additions & 1 deletion test/helper.rb
Expand Up @@ -49,7 +49,8 @@ def test_default
end unless defined? ::MiniTest

def capture_warnings
old, $stderr = $stderr, StringIO.new
old = $stderr
$stderr = StringIO.new
begin
yield
$stderr.string
Expand Down