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

Add latest rubocop and use Ruby 2.6+ #1311

Merged
merged 20 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 144 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require:
AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.4
TargetRubyVersion: 2.6

Inclusivity/Race:
Enabled: true
Expand Down Expand Up @@ -60,3 +60,146 @@ Style/IfUnlessModifier:
Style/SlicingWithRange: # (0.83)
Enabled: true

Layout/BeginEndAlignment: # (new in 0.91)
Enabled: true
Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
Enabled: true
Lint/ConstantDefinitionInBlock: # (new in 0.91)
Enabled: true
Lint/DuplicateElsifCondition: # (new in 0.88)
Enabled: true
Lint/DuplicateRequire: # (new in 0.90)
Enabled: true
Lint/DuplicateRescueException: # (new in 0.89)
Enabled: true
Lint/EmptyConditionalBody: # (new in 0.89)
Enabled: true
Lint/EmptyFile: # (new in 0.90)
Enabled: true
Lint/FloatComparison: # (new in 0.89)
Enabled: true
Lint/HashCompareByIdentity: # (new in 0.93)
Enabled: true
Lint/IdentityComparison: # (new in 0.91)
Enabled: true
Lint/MissingSuper: # (new in 0.89)
Enabled: true
Lint/MixedRegexpCaptureTypes: # (new in 0.85)
Enabled: true
Lint/OutOfRangeRegexpRef: # (new in 0.89)
Enabled: true
Lint/RedundantSafeNavigation: # (new in 0.93)
Enabled: true
Lint/SelfAssignment: # (new in 0.89)
Enabled: true
Lint/TopLevelReturnWithArgument: # (new in 0.89)
Enabled: true
Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
Enabled: true
Performance/BlockGivenWithExplicitBlock: # (new in 1.9)
Enabled: true
Performance/CollectionLiteralInLoop: # (new in 1.8)
Enabled: true
Performance/ConstantRegexp: # (new in 1.9)
Enabled: true
Performance/MethodObjectAsBlock: # (new in 1.9)
Enabled: true
Performance/RedundantEqualityComparisonBlock: # (new in 1.10)
Enabled: true
Performance/RedundantSortBlock: # (new in 1.7)
Enabled: true
Performance/RedundantSplitRegexpArgument: # (new in 1.10)
Enabled: true
Performance/RedundantStringChars: # (new in 1.7)
Enabled: true
Performance/ReverseFirst: # (new in 1.7)
Enabled: true
Performance/SortReverse: # (new in 1.7)
Enabled: true
Performance/Squeeze: # (new in 1.7)
Enabled: true
Performance/StringInclude: # (new in 1.7)
Enabled: true
Performance/Sum: # (new in 1.8)
Enabled: true

Gemspec/DateAssignment: # (new in 1.10)
Enabled: true
Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
Enabled: true
Layout/SpaceBeforeBrackets: # (new in 1.7)
Enabled: true
Lint/AmbiguousAssignment: # (new in 1.7)
Enabled: true
Lint/AmbiguousRange: # (new in 1.19)
Enabled: true
Lint/DeprecatedConstants: # (new in 1.8)
Enabled: true
Lint/DuplicateBranch: # (new in 1.3)
Enabled: true
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
Enabled: true
Lint/EmptyBlock: # (new in 1.1)
Enabled: true
Lint/EmptyClass: # (new in 1.3)
Enabled: true
Lint/EmptyInPattern: # (new in 1.16)
Enabled: true
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
Enabled: true
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
Enabled: true
Lint/NumberedParameterAssignment: # (new in 1.9)
Enabled: true
Lint/OrAssignmentToConstant: # (new in 1.9)
Enabled: true
Lint/RedundantDirGlobSort: # (new in 1.8)
Enabled: true
Lint/SymbolConversion: # (new in 1.9)
Enabled: true
Lint/ToEnumArguments: # (new in 1.1)
Enabled: true
Lint/TripleQuotes: # (new in 1.9)
Enabled: true
Lint/UnexpectedBlockArity: # (new in 1.5)
Enabled: true
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
Enabled: true
Naming/InclusiveLanguage: # (new in 1.18)
Enabled: true
Style/ArgumentsForwarding: # (new in 1.1)
Enabled: true
Style/CollectionCompact: # (new in 1.2)
Enabled: true
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
Enabled: true
Style/EndlessMethod: # (new in 1.8)
Enabled: true
Style/HashConversion: # (new in 1.10)
Enabled: true
Style/HashExcept: # (new in 1.7)
Enabled: true
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
Enabled: true
Style/InPatternThen: # (new in 1.16)
Enabled: true
Style/MultilineInPatternThen: # (new in 1.16)
Enabled: true
Style/NegatedIfElseCondition: # (new in 1.2)
Enabled: true
Style/NilLambda: # (new in 1.3)
Enabled: true
Style/QuotedSymbols: # (new in 1.16)
Enabled: true
Style/RedundantArgument: # (new in 1.4)
Enabled: true
Style/RedundantSelfAssignmentBranch: # (new in 1.19)
Enabled: true
Style/StringChars: # (new in 1.12)
Enabled: true
Style/SwapValues: # (new in 1.1)
Enabled: true
Performance/AncestorsInclude: # (new in 1.7)
Enabled: true
Performance/BigDecimalWithNumericArgument: # (new in 1.7)
Enabled: true
79 changes: 69 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,91 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-04-14 06:51:37 UTC using RuboCop version 0.90.0.
# on 2021-08-16 15:31:43 UTC using RuboCop version 1.19.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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 26
# Configuration parameters: IgnoredMethods.
# Offense count: 7
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/faraday/composite_read_io_spec.rb'
- 'spec/faraday/options/options_spec.rb'
- 'spec/faraday/rack_builder_spec.rb'
- 'spec/faraday/request/instrumentation_spec.rb'

# Offense count: 11
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'spec/faraday/connection_spec.rb'
- 'spec/faraday/rack_builder_spec.rb'
- 'spec/faraday/response_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowedMethods.
# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
Lint/RedundantSafeNavigation:
Exclude:
- 'lib/faraday/connection.rb'

# Offense count: 16
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 42

# Offense count: 5
# Offense count: 3
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 256
Max: 226

# Offense count: 15
# Offense count: 12
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 13

# Offense count: 43
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
# Offense count: 27
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 37
Max: 33

# Offense count: 9
# Offense count: 8
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 14

# Offense count: 4
# Cop supports --auto-correct.
Performance/BlockGivenWithExplicitBlock:
Exclude:
- 'lib/faraday/options.rb'
- 'lib/faraday/rack_builder.rb'

# Offense count: 1
# Cop supports --auto-correct.
Performance/RedundantSplitRegexpArgument:
Exclude:
- 'lib/faraday/utils/headers.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.
Performance/StringInclude:
Exclude:
- 'spec/support/fake_safe_buffer.rb'

# Offense count: 3
Style/DocumentDynamicEvalDefinition:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to talk a bit about this rule, since the fix will have visual impact, and we'd like to pick the nicest alternative.

Exclude:
- 'lib/faraday/connection.rb'
- 'lib/faraday/options.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/PerlBackrefs:
Exclude:
- 'lib/faraday/encoders/nested_params_encoder.rb'
- 'spec/support/fake_safe_buffer.rb'
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ group :development, :test do
end

group :development, :lint do
gem 'rubocop', '~> 0.90.0'
gem 'rubocop'
gem 'rubocop-inclusivity', '~> 1.0'
gem 'rubocop-packaging', '~> 0.5'
gem 'rubocop-performance', '~> 1.0'
Expand Down
2 changes: 1 addition & 1 deletion examples/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_sushi_name
stubs.verify_stubbed_calls
end

def test_sushi_404
def test_sushi_not_found
stubs = Faraday::Adapter::Test::Stubs.new
stubs.get('/ebi') do
[
Expand Down
2 changes: 1 addition & 1 deletion faraday.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://lostisland.github.io/faraday'
spec.licenses = ['MIT']

spec.required_ruby_version = '>= 2.4'
spec.required_ruby_version = '>= 2.6'

spec.add_dependency 'faraday-net_http', '~> 1.0'
spec.add_dependency 'multipart-post', '>= 1.2', '< 3'
Expand Down
4 changes: 1 addition & 3 deletions lib/faraday/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,12 @@ def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
if url && base.path && base.path !~ %r{/$}
base.path = "#{base.path}/" # ensure trailing slash
end
url = url && URI.parse(url.to_s).opaque ? url.to_s.gsub(':', '%3A') : url
url = url.to_s.gsub(':', '%3A') if url && URI.parse(url.to_s).opaque
uri = url ? base + url : base
if params
uri.query = params.to_query(params_encoder || options.params_encoder)
end
# rubocop:disable Style/SafeNavigation
uri.query = nil if uri.query && uri.query.empty?
# rubocop:enable Style/SafeNavigation
uri
end

Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/encoders/nested_params_encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def new_context(subkey, is_array, context)
value_type = is_array ? Array : Hash
if context[subkey] && !context[subkey].is_a?(value_type)
raise TypeError, "expected #{value_type.name} " \
"(got #{context[subkey].class.name}) for param `#{subkey}'"
"(got #{context[subkey].class.name}) for param `#{subkey}'"
end

context[subkey] ||= value_type.new
Expand Down
6 changes: 3 additions & 3 deletions lib/faraday/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def finished?
end

def on_complete(&block)
if !finished?
@on_complete_callbacks << block
else
if finished?
yield(env)
else
@on_complete_callbacks << block
end
self
end
Expand Down
4 changes: 2 additions & 2 deletions spec/faraday/options/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@

it 'retains custom members' do
env[:foo] = 'custom 1'
env[:bar] = :custom_2
env[:bar] = :custom2
env2 = Faraday::Env.from(env)
env2[:baz] = 'custom 3'

expect(env2[:foo]).to eq('custom 1')
expect(env2[:bar]).to eq(:custom_2)
expect(env2[:bar]).to eq(:custom2)
expect(env[:baz]).to be_nil
end

Expand Down
2 changes: 2 additions & 0 deletions spec/faraday/rack_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def call(env)

class Apple < Handler
end

class Orange < Handler
end

class Banana < Handler
end

Expand Down
12 changes: 5 additions & 7 deletions spec/faraday/request/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ def instrument(name, env)

it { expect(options.name).to eq('request.faraday') }
it 'defaults to ActiveSupport::Notifications' do
begin
res = options.instrumenter
rescue NameError => e
expect(e.to_s).to match('ActiveSupport')
else
expect(res).to eq(ActiveSupport::Notifications)
end
res = options.instrumenter
rescue NameError => e
expect(e.to_s).to match('ActiveSupport')
else
expect(res).to eq(ActiveSupport::Notifications)
end

it 'instruments with default name' do
Expand Down
10 changes: 4 additions & 6 deletions spec/faraday/response/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ def process(body, content_type = 'application/json', options = {})
end

it 'includes the response on the ParsingError instance' do
begin
process('{') { |env| env[:response] = Faraday::Response.new }
raise 'Parsing should have failed.'
rescue Faraday::ParsingError => e
expect(e.response).to be_a(Faraday::Response)
end
process('{') { |env| env[:response] = Faraday::Response.new }
raise 'Parsing should have failed.'
rescue Faraday::ParsingError => e
expect(e.response).to be_a(Faraday::Response)
end

context 'HEAD responses' do
Expand Down
2 changes: 1 addition & 1 deletion spec/faraday/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe 'headers parsing' do
let(:multi_response_headers) do
"HTTP/1.x 500 OK\r\nContent-Type: text/html; charset=UTF-8\r\n" \
"HTTP/1.x 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n"
"HTTP/1.x 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n"
end

it 'parse headers for aggregated responses' do
Expand Down
Loading