Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update RuboCop
Browse files Browse the repository at this point in the history
Require its specific version in `Gemfile`.

Fix it's installation in CI.

Enable new cops.

Resolve new offenses.

Drop support of Ruby 2.3
(it's not supported by RuboCop and by MRI:https://www.ruby-lang.org/en/news/2019/03/31/support-of-ruby-2-3-has-ended/)
AlexWayfer committed Apr 17, 2020
1 parent 3b3de79 commit c751e03
Showing 11 changed files with 51 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ jobs:

- name: Rubocop
run: |
gem install rubocop rubocop-performance --no-document
rubocop --require rubocop-performance --format progress
bundle install
bundle exec rubocop --format progress
- name: Yard-Junk
run: |
19 changes: 18 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ require:
AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.3
TargetRubyVersion: 2.4

Metrics/BlockLength:
Exclude:
@@ -18,10 +18,27 @@ Layout/LineLength:
- spec/**/*.rb
- examples/**/*.rb

Layout/SpaceAroundMethodCallOperator:
Enabled: true

Style/DoubleNegation:
Enabled: false

Style/Documentation:
Exclude:
- 'spec/**/*'
- 'examples/**/*'

Style/ExponentialNotation:
Enabled: true
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true

Lint/RaiseException:
Enabled: true
Lint/StructNewOverride:
Enabled: true
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@ group :development, :test do
gem 'pry'
end

group :lint, :test do
gem 'rubocop', '~> 0.82.0'
gem 'rubocop-performance', '~> 1.0'
end

group :test do
gem 'coveralls', require: false
gem 'em-http-request', '>= 1.1', require: 'em-http'
@@ -24,7 +29,6 @@ group :test do
gem 'rack-test', '>= 0.6', require: 'rack/test'
gem 'rspec', '~> 3.7'
gem 'rspec_junit_formatter', '~> 0.4'
gem 'rubocop-performance', '~> 1.0'
gem 'simplecov'
gem 'typhoeus', '~> 1.3',
git: 'https://github.com/typhoeus/typhoeus.git',
2 changes: 1 addition & 1 deletion faraday.gemspec
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://lostisland.github.io/faraday'
spec.licenses = ['MIT']

spec.required_ruby_version = '>= 2.3'
spec.required_ruby_version = '>= 2.4'

spec.add_dependency 'multipart-post', '>= 1.2', '< 3'

4 changes: 2 additions & 2 deletions lib/faraday/adapter/excon.rb
Original file line number Diff line number Diff line change
@@ -34,9 +34,9 @@ def call(env)

@app.call(env)
rescue ::Excon::Errors::SocketError => e
raise Faraday::TimeoutError, e if e.message =~ /\btimeout\b/
raise Faraday::TimeoutError, e if e.message.match?(/\btimeout\b/)

raise Faraday::SSLError, e if e.message =~ /\bcertificate\b/
raise Faraday::SSLError, e if e.message.match?(/\bcertificate\b/)

raise Faraday::ConnectionFailed, e
rescue ::Excon::Errors::Timeout => e
2 changes: 1 addition & 1 deletion lib/faraday/autoload.rb
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ module AutoloadHelper
#
# @return [void]
def autoload_all(prefix, options)
if prefix =~ %r{^faraday(/|$)}i
if prefix.match? %r{^faraday(/|$)}i
prefix = File.join(Faraday.root_path, prefix)
end

2 changes: 1 addition & 1 deletion lib/faraday/connection.rb
Original file line number Diff line number Diff line change
@@ -593,7 +593,7 @@ def find_default_proxy
uri = ENV['http_proxy']
return unless uri && !uri.empty?

uri = 'http://' + uri if uri !~ /^http/i
uri = 'http://' + uri unless uri.match?(/^http/i)
uri
end

4 changes: 2 additions & 2 deletions lib/faraday/rack_builder.rb
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@ def dup
end

# ENV Keys
# :method - a symbolized request method (:get, :post)
# :http_method - a symbolized request HTTP method (:get, :post)
# :body - the request body that will eventually be converted to a string.
# :url - URI instance for the current request.
# :status - HTTP response status code
@@ -207,7 +207,7 @@ def build_env(connection, request)
request.options.params_encoder
)

Env.new(request.method, request.body, exclusive_url,
Env.new(request.http_method, request.body, exclusive_url,
request.options, request.headers, connection.ssl,
connection.parallel_manager)
end
22 changes: 12 additions & 10 deletions lib/faraday/request.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ module Faraday
# req.body = 'abc'
# end
#
# @!attribute method
# @!attribute http_method
# @return [Symbol] the HTTP method of the Request
# @!attribute path
# @return [URI, String] the path
@@ -26,7 +26,9 @@ module Faraday
# @return [RequestOptions] options
#
# rubocop:disable Style/StructInheritance
class Request < Struct.new(:method, :path, :params, :headers, :body, :options)
class Request < Struct.new(
:http_method, :path, :params, :headers, :body, :options
)
# rubocop:enable Style/StructInheritance

extend MiddlewareRegistry
@@ -116,7 +118,7 @@ def []=(key, value)
# @return [Hash] the hash ready to be serialized in Marshal.
def marshal_dump
{
method: method,
http_method: http_method,
body: body,
headers: headers,
path: path,
@@ -129,17 +131,17 @@ def marshal_dump
# Restores the instance variables according to the +serialised+.
# @param serialised [Hash] the serialised object.
def marshal_load(serialised)
self.method = serialised[:method]
self.body = serialised[:body]
self.headers = serialised[:headers]
self.path = serialised[:path]
self.params = serialised[:params]
self.options = serialised[:options]
self.http_method = serialised[:http_method]
self.body = serialised[:body]
self.headers = serialised[:headers]
self.path = serialised[:path]
self.params = serialised[:params]
self.options = serialised[:options]
end

# @return [Env] the Env for this Request
def to_env(connection)
Env.new(method, body, connection.build_exclusive_url(path, params),
Env.new(http_method, body, connection.build_exclusive_url(path, params),
options, headers, connection.ssl, connection.parallel_manager)
end
end
2 changes: 1 addition & 1 deletion script/proxy-server
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ if (found = ARGV.index('-u'))
end

match_credentials = lambda { |credentials|
got_username, got_password = credentials.to_s.unpack('m*')[0].split(':', 2)
got_username, got_password = credentials.to_s.unpack1('m*')[0].split(':', 2)
got_username == username && got_password == password
}

12 changes: 6 additions & 6 deletions spec/faraday/request_spec.rb
Original file line number Diff line number Diff line change
@@ -6,20 +6,20 @@
headers: { 'Mime-Version' => '1.0' },
request: { oauth: { consumer_key: 'anonymous' } })
end
let(:method) { :get }
let(:http_method) { :get }
let(:block) { nil }

subject { conn.build_request(method, &block) }
subject { conn.build_request(http_method, &block) }

context 'when nothing particular is configured' do
it { expect(subject.method).to eq(:get) }
it { expect(subject.http_method).to eq(:get) }
it { expect(subject.to_env(conn).ssl.verify).to be_falsey }
end

context 'when method is post' do
let(:method) { :post }
context 'when HTTP method is post' do
let(:http_method) { :post }

it { expect(subject.method).to eq(:post) }
it { expect(subject.http_method).to eq(:post) }
end

context 'when setting the url on setup with a URI' do

0 comments on commit c751e03

Please sign in to comment.