From 5bdee0306f95849d03505f580ca87d4101b63fb6 Mon Sep 17 00:00:00 2001 From: Mattia Giuffrida Date: Mon, 8 Aug 2022 15:33:37 +0100 Subject: [PATCH] Enables and fixes all new cops. Fixes #1440 --- .rubocop.yml | 204 ++++++++++++------------ .rubocop_todo.yml | 29 ++-- lib/faraday/adapter/test.rb | 2 +- lib/faraday/connection.rb | 2 +- spec/faraday/connection_spec.rb | 14 +- spec/support/shared_examples/adapter.rb | 2 +- 6 files changed, 124 insertions(+), 129 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5b216ee12..58fc54991 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,196 +9,188 @@ AllCops: DisplayStyleGuide: true TargetRubyVersion: 2.6 -Metrics/BlockLength: +# Custom config +Gemspec/RequireMFA: # we don't know if this works with auto-deployments yet + Enabled: false +Layout/LineLength: Exclude: - spec/**/*.rb - examples/**/*.rb - -Metrics/ParameterLists: - Max: 6 - -Layout/EmptyLinesAroundAttributeAccessor: # (0.83) - Enabled: true - -Layout/LineLength: +Metrics/BlockLength: Exclude: - spec/**/*.rb - examples/**/*.rb - -Layout/SpaceAroundMethodCallOperator: - Enabled: true - -Lint/DeprecatedOpenSSLConstant: # (0.84) - Enabled: true - -Lint/RaiseException: - Enabled: true - -Lint/StructNewOverride: - Enabled: true - -Style/DoubleNegation: - Enabled: false - Style/Documentation: Exclude: - 'spec/**/*' - 'examples/**/*' +Style/DoubleNegation: + Enabled: false +Style/IfUnlessModifier: + Enabled: false -Style/ExponentialNotation: +# New cops +Gemspec/DeprecatedAttributeAssignment: # new in 1.30 Enabled: true -Style/HashEachMethods: +Layout/LineContinuationLeadingSpace: # new in 1.31 Enabled: true -Style/HashTransformKeys: +Layout/LineContinuationSpacing: # new in 1.31 Enabled: true -Style/HashTransformValues: +Layout/LineEndStringConcatenationIndentation: # new in 1.18 Enabled: true -Style/IfUnlessModifier: - Enabled: false - -Style/SlicingWithRange: # (0.83) +Layout/SpaceBeforeBrackets: # new in 1.7 Enabled: true - -Layout/BeginEndAlignment: # (new in 0.91) +Lint/AmbiguousAssignment: # new in 1.7 Enabled: true -Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89) +Lint/AmbiguousOperatorPrecedence: # new in 1.21 Enabled: true -Lint/ConstantDefinitionInBlock: # (new in 0.91) +Lint/AmbiguousRange: # new in 1.19 Enabled: true -Lint/DuplicateElsifCondition: # (new in 0.88) +Lint/ConstantOverwrittenInRescue: # new in 1.31 Enabled: true -Lint/DuplicateRequire: # (new in 0.90) +Lint/DeprecatedConstants: # new in 1.8 Enabled: true -Lint/DuplicateRescueException: # (new in 0.89) +Lint/DuplicateBranch: # new in 1.3 Enabled: true -Lint/EmptyConditionalBody: # (new in 0.89) +Lint/DuplicateRegexpCharacterClassElement: # new in 1.1 Enabled: true -Lint/EmptyFile: # (new in 0.90) +Lint/EmptyBlock: # new in 1.1 Enabled: true -Lint/FloatComparison: # (new in 0.89) +Lint/EmptyClass: # new in 1.3 Enabled: true -Lint/HashCompareByIdentity: # (new in 0.93) +Lint/EmptyInPattern: # new in 1.16 Enabled: true -Lint/IdentityComparison: # (new in 0.91) +Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21 Enabled: true -Lint/MissingSuper: # (new in 0.89) +Lint/LambdaWithoutLiteralBlock: # new in 1.8 Enabled: true -Lint/MixedRegexpCaptureTypes: # (new in 0.85) +Lint/NoReturnInBeginEndBlocks: # new in 1.2 Enabled: true -Lint/OutOfRangeRegexpRef: # (new in 0.89) +Lint/NonAtomicFileOperation: # new in 1.31 Enabled: true -Lint/RedundantSafeNavigation: # (new in 0.93) +Lint/NumberedParameterAssignment: # new in 1.9 Enabled: true -Lint/SelfAssignment: # (new in 0.89) +Lint/OrAssignmentToConstant: # new in 1.9 Enabled: true -Lint/TopLevelReturnWithArgument: # (new in 0.89) +Lint/RedundantDirGlobSort: # new in 1.8 Enabled: true -Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90) +Lint/RefinementImportMethods: # new in 1.27 Enabled: true -Performance/BlockGivenWithExplicitBlock: # (new in 1.9) +Lint/RequireRangeParentheses: # new in 1.32 Enabled: true -Performance/CollectionLiteralInLoop: # (new in 1.8) +Lint/RequireRelativeSelfPath: # new in 1.22 Enabled: true -Performance/ConstantRegexp: # (new in 1.9) +Lint/SymbolConversion: # new in 1.9 Enabled: true -Performance/MethodObjectAsBlock: # (new in 1.9) +Lint/ToEnumArguments: # new in 1.1 Enabled: true -Performance/RedundantEqualityComparisonBlock: # (new in 1.10) +Lint/TripleQuotes: # new in 1.9 Enabled: true -Performance/RedundantSortBlock: # (new in 1.7) +Lint/UnexpectedBlockArity: # new in 1.5 Enabled: true -Performance/RedundantSplitRegexpArgument: # (new in 1.10) +Lint/UnmodifiedReduceAccumulator: # new in 1.1 Enabled: true -Performance/RedundantStringChars: # (new in 1.7) +Lint/UselessRuby2Keywords: # new in 1.23 Enabled: true -Performance/ReverseFirst: # (new in 1.7) +Naming/BlockForwarding: # new in 1.24 Enabled: true -Performance/SortReverse: # (new in 1.7) +Security/CompoundHash: # new in 1.28 Enabled: true -Performance/Squeeze: # (new in 1.7) +Security/IoMethods: # new in 1.22 Enabled: true -Performance/StringInclude: # (new in 1.7) +Style/ArgumentsForwarding: # new in 1.1 Enabled: true -Performance/Sum: # (new in 1.8) +Style/CollectionCompact: # new in 1.2 Enabled: true - -Gemspec/DeprecatedAttributeAssignment: +Style/DocumentDynamicEvalDefinition: # new in 1.1 + Enabled: true +Style/EmptyHeredoc: # new in 1.32 + Enabled: true +Style/EndlessMethod: # new in 1.8 + Enabled: true +Style/EnvHome: # new in 1.29 + Enabled: true +Style/FetchEnvVar: # new in 1.28 + Enabled: true +Style/FileRead: # new in 1.24 + Enabled: true +Style/FileWrite: # new in 1.24 Enabled: true -Layout/LineEndStringConcatenationIndentation: # (new in 1.18) +Style/HashConversion: # new in 1.10 Enabled: true -Layout/SpaceBeforeBrackets: # (new in 1.7) +Style/HashExcept: # new in 1.7 Enabled: true -Lint/AmbiguousAssignment: # (new in 1.7) +Style/IfWithBooleanLiteralBranches: # new in 1.9 Enabled: true -Lint/AmbiguousRange: # (new in 1.19) +Style/InPatternThen: # new in 1.16 Enabled: true -Lint/DeprecatedConstants: # (new in 1.8) +Style/MapCompactWithConditionalBlock: # new in 1.30 Enabled: true -Lint/DuplicateBranch: # (new in 1.3) +Style/MapToHash: # new in 1.24 Enabled: true -Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1) +Style/MultilineInPatternThen: # new in 1.16 Enabled: true -Lint/EmptyBlock: # (new in 1.1) +Style/NegatedIfElseCondition: # new in 1.2 Enabled: true -Lint/EmptyClass: # (new in 1.3) +Style/NestedFileDirname: # new in 1.26 Enabled: true -Lint/EmptyInPattern: # (new in 1.16) +Style/NilLambda: # new in 1.3 Enabled: true -Lint/LambdaWithoutLiteralBlock: # (new in 1.8) +Style/NumberedParameters: # new in 1.22 Enabled: true -Lint/NoReturnInBeginEndBlocks: # (new in 1.2) +Style/NumberedParametersLimit: # new in 1.22 Enabled: true -Lint/NumberedParameterAssignment: # (new in 1.9) +Style/ObjectThen: # new in 1.28 Enabled: true -Lint/OrAssignmentToConstant: # (new in 1.9) +Style/OpenStructUse: # new in 1.23 Enabled: true -Lint/RedundantDirGlobSort: # (new in 1.8) +Style/QuotedSymbols: # new in 1.16 Enabled: true -Lint/SymbolConversion: # (new in 1.9) +Style/RedundantArgument: # new in 1.4 Enabled: true -Lint/ToEnumArguments: # (new in 1.1) +Style/RedundantInitialize: # new in 1.27 Enabled: true -Lint/TripleQuotes: # (new in 1.9) +Style/RedundantSelfAssignmentBranch: # new in 1.19 Enabled: true -Lint/UnexpectedBlockArity: # (new in 1.5) +Style/SelectByRegexp: # new in 1.22 Enabled: true -Lint/UnmodifiedReduceAccumulator: # (new in 1.1) +Style/StringChars: # new in 1.12 Enabled: true -Naming/InclusiveLanguage: # (new in 1.18) +Style/SwapValues: # new in 1.1 Enabled: true -Style/ArgumentsForwarding: # (new in 1.1) +Performance/AncestorsInclude: # new in 1.7 Enabled: true -Style/CollectionCompact: # (new in 1.2) +Performance/BigDecimalWithNumericArgument: # new in 1.7 Enabled: true -Style/DocumentDynamicEvalDefinition: # (new in 1.1) +Performance/BlockGivenWithExplicitBlock: # new in 1.9 Enabled: true -Style/EndlessMethod: # (new in 1.8) +Performance/CollectionLiteralInLoop: # new in 1.8 Enabled: true -Style/HashConversion: # (new in 1.10) +Performance/ConcurrentMonotonicTime: # new in 1.12 Enabled: true -Style/HashExcept: # (new in 1.7) +Performance/ConstantRegexp: # new in 1.9 Enabled: true -Style/IfWithBooleanLiteralBranches: # (new in 1.9) +Performance/MapCompact: # new in 1.11 Enabled: true -Style/InPatternThen: # (new in 1.16) +Performance/MethodObjectAsBlock: # new in 1.9 Enabled: true -Style/MultilineInPatternThen: # (new in 1.16) +Performance/RedundantEqualityComparisonBlock: # new in 1.10 Enabled: true -Style/NegatedIfElseCondition: # (new in 1.2) +Performance/RedundantSortBlock: # new in 1.7 Enabled: true -Style/NilLambda: # (new in 1.3) +Performance/RedundantSplitRegexpArgument: # new in 1.10 Enabled: true -Style/QuotedSymbols: # (new in 1.16) +Performance/RedundantStringChars: # new in 1.7 Enabled: true -Style/RedundantArgument: # (new in 1.4) +Performance/ReverseFirst: # new in 1.7 Enabled: true -Style/RedundantSelfAssignmentBranch: # (new in 1.19) +Performance/SortReverse: # new in 1.7 Enabled: true -Style/StringChars: # (new in 1.12) +Performance/Squeeze: # new in 1.7 Enabled: true -Style/SwapValues: # (new in 1.1) +Performance/StringIdentifierArgument: # new in 1.13 Enabled: true -Performance/AncestorsInclude: # (new in 1.7) +Performance/StringInclude: # new in 1.7 Enabled: true -Performance/BigDecimalWithNumericArgument: # (new in 1.7) +Performance/Sum: # new in 1.8 Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e83aacf5d..fbec6de43 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,17 +1,16 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2021-08-16 15:31:43 UTC using RuboCop version 1.19.0. +# on 2022-08-08 14:26:32 UTC using RuboCop version 1.33.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: 7 +# Offense count: 6 # 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' @@ -24,28 +23,33 @@ Lint/EmptyBlock: - 'spec/faraday/rack_builder_spec.rb' - 'spec/faraday/response_spec.rb' -# Offense count: 16 -# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. +# Offense count: 12 +# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: Max: 42 -# Offense count: 3 +# Offense count: 4 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: Max: 230 -# Offense count: 12 -# Configuration parameters: IgnoredMethods. +# Offense count: 9 +# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods. Metrics/CyclomaticComplexity: Max: 13 -# Offense count: 27 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +# Offense count: 26 +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods. Metrics/MethodLength: Max: 33 -# Offense count: 8 -# Configuration parameters: IgnoredMethods. +# Offense count: 1 +# Configuration parameters: CountKeywordArgs, MaxOptionalParameters. +Metrics/ParameterLists: + Max: 6 + +# Offense count: 6 +# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods. Metrics/PerceivedComplexity: Max: 14 @@ -54,4 +58,3 @@ Style/DocumentDynamicEvalDefinition: Exclude: - 'lib/faraday/connection.rb' - 'lib/faraday/options.rb' - diff --git a/lib/faraday/adapter/test.rb b/lib/faraday/adapter/test.rb index 9e539e615..55adfd633 100644 --- a/lib/faraday/adapter/test.rb +++ b/lib/faraday/adapter/test.rb @@ -272,7 +272,7 @@ def call(env) stub, meta = stubs.match(env) unless stub - raise Stubs::NotFound, "no stubbed request for #{env[:method]} "\ + raise Stubs::NotFound, "no stubbed request for #{env[:method]} " \ "#{env[:url]} #{env[:body]}" end diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index ff1e5b801..36728568a 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -537,7 +537,7 @@ def proxy_from_env(url) end def find_default_proxy - uri = ENV['http_proxy'] + uri = ENV.fetch('http_proxy', nil) return unless uri && !uri.empty? uri = "http://#{uri}" unless uri.match?(/^http/i) diff --git a/spec/faraday/connection_spec.rb b/spec/faraday/connection_spec.rb index e53d095d0..05d9c280b 100644 --- a/spec/faraday/connection_spec.rb +++ b/spec/faraday/connection_spec.rb @@ -6,7 +6,7 @@ def encode(params) end def decode(params) - params.split(',').map { |pair| pair.split('-') }.to_h + params.split(',').to_h { |pair| pair.split('-') } end end @@ -511,7 +511,7 @@ def decode(params) it 'uses env http_proxy' do with_env 'http_proxy' => 'http://proxy.com' do conn = Faraday.new - expect(conn.instance_variable_get('@manual_proxy')).to be_falsey + expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey expect(conn.proxy_for_request('http://google.co.uk').host).to eq('proxy.com') end end @@ -519,7 +519,7 @@ def decode(params) it 'uses processes no_proxy before http_proxy' do with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'google.co.uk' do conn = Faraday.new - expect(conn.instance_variable_get('@manual_proxy')).to be_falsey + expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey expect(conn.proxy_for_request('http://google.co.uk')).to be_nil end end @@ -527,7 +527,7 @@ def decode(params) it 'uses env https_proxy' do with_env 'https_proxy' => 'https://proxy.com' do conn = Faraday.new - expect(conn.instance_variable_get('@manual_proxy')).to be_falsey + expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey expect(conn.proxy_for_request('https://google.co.uk').host).to eq('proxy.com') end end @@ -535,7 +535,7 @@ def decode(params) it 'uses processes no_proxy before https_proxy' do with_env 'https_proxy' => 'https://proxy.com', 'no_proxy' => 'google.co.uk' do conn = Faraday.new - expect(conn.instance_variable_get('@manual_proxy')).to be_falsey + expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey expect(conn.proxy_for_request('https://google.co.uk')).to be_nil end end @@ -545,7 +545,7 @@ def decode(params) conn = Faraday.new conn.proxy = 'http://proxy2.com' - expect(conn.instance_variable_get('@manual_proxy')).to be_truthy + expect(conn.instance_variable_get(:@manual_proxy)).to be_truthy expect(conn.proxy_for_request('https://google.co.uk').host).to eq('proxy2.com') end end @@ -580,7 +580,7 @@ def decode(params) end conn.get(url) - expect(conn.instance_variable_get('@temp_proxy')).to be_nil + expect(conn.instance_variable_get(:@temp_proxy)).to be_nil end it 'dynamically check no proxy' do diff --git a/spec/support/shared_examples/adapter.rb b/spec/support/shared_examples/adapter.rb index 4cf09a23d..625690883 100644 --- a/spec/support/shared_examples/adapter.rb +++ b/spec/support/shared_examples/adapter.rb @@ -37,7 +37,7 @@ let(:conn) do conn_options[:ssl] ||= {} - conn_options[:ssl][:ca_file] ||= ENV['SSL_FILE'] + conn_options[:ssl][:ca_file] ||= ENV.fetch('SSL_FILE', nil) conn_options[:ssl][:verify_hostname] ||= ENV['SSL_VERIFY_HOSTNAME'] == 'yes' Faraday.new(remote, conn_options) do |conn|