Skip to content

Commit

Permalink
Merge 56a2456 into fe600c7
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle committed Aug 16, 2021
2 parents fe600c7 + 56a2456 commit 37abccd
Show file tree
Hide file tree
Showing 18 changed files with 221 additions and 54 deletions.
149 changes: 144 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-inclusivity
- rubocop-packaging
- rubocop-performance

AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.4

Inclusivity/Race:
Enabled: true
TargetRubyVersion: 2.6

Metrics/BlockLength:
Exclude:
Expand Down Expand Up @@ -60,3 +56,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
53 changes: 43 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
# 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: 3
Style/DocumentDynamicEvalDefinition:
Exclude:
- 'lib/faraday/connection.rb'
- 'lib/faraday/options.rb'

3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ group :development, :test do
end

group :development, :lint do
gem 'rubocop', '~> 0.90.0'
gem 'rubocop-inclusivity', '~> 1.0'
gem 'rubocop'
gem 'rubocop-packaging', '~> 0.5'
gem 'rubocop-performance', '~> 1.0'
gem 'yard-junk'
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
4 changes: 2 additions & 2 deletions lib/faraday/encoders/nested_params_encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def decode_pair(key, value, context)
subkeys = key.scan(SUBKEYS_REGEX)
subkeys.each_with_index do |subkey, i|
is_array = subkey =~ /[\[\]]+\Z/
subkey = $` if is_array
subkey = Regexp.last_match.pre_match if is_array
last_subkey = i == subkeys.length - 1

context = prepare_context(context, subkey, is_array, last_subkey)
Expand All @@ -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/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def empty?

# Public
def each_key(&block)
return to_enum(:each_key) unless block_given?
return to_enum(:each_key) unless block

keys.each(&block)
end
Expand All @@ -118,7 +118,7 @@ def key?(key)

# Public
def each_value(&block)
return to_enum(:each_value) unless block_given?
return to_enum(:each_value) unless block

values.each(&block)
end
Expand Down Expand Up @@ -168,7 +168,7 @@ def self.attribute_options
end

def self.memoized(key, &block)
unless block_given?
unless block
raise ArgumentError, '#memoized must be called with a block'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/rack_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def build(app = nil)
def initialize(handlers = [], adapter = nil, &block)
@adapter = adapter
@handlers = handlers
if block_given?
if block
build(&block)
elsif @handlers.empty?
# default stack, if nothing else is configured
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
2 changes: 1 addition & 1 deletion lib/faraday/utils/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def to_hash
def parse(header_string)
return unless header_string && !header_string.empty?

headers = header_string.split(/\r\n/)
headers = header_string.split("\r\n")

# Find the last set of response headers.
start_index = headers.rindex { |x| x.start_with?('HTTP/') } || 0
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
Loading

0 comments on commit 37abccd

Please sign in to comment.