From c9680332ad5c008444a70d1e7908bcbbf9e92243 Mon Sep 17 00:00:00 2001 From: Mattia Giuffrida Date: Wed, 27 Dec 2023 10:35:52 +0000 Subject: [PATCH 1/6] Make 3.0 the minimum supported Ruby version --- .rubocop.yml | 2 +- README.md | 2 +- faraday.gemspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3617caa06..c359f4bf6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,7 +7,7 @@ require: AllCops: DisplayCopNames: true DisplayStyleGuide: true - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.0 # Custom config Gemspec/RequireMFA: # we don't know if this works with auto-deployments yet diff --git a/README.md b/README.md index 596b5808f..0cca6db87 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Need more details? See the [Faraday API Documentation][apidoc] to see how it wor This library aims to support and is [tested against][actions] the currently officially supported Ruby implementations. This means that, even without a major release, we could add or drop support for Ruby versions, following their [EOL](https://endoflife.date/ruby). -Currently that means we support Ruby 2.6+ +Currently that means we support Ruby 3.0+ If something doesn't work on one of these Ruby versions, it's a bug. diff --git a/faraday.gemspec b/faraday.gemspec index 112763235..ed9b4ab18 100644 --- a/faraday.gemspec +++ b/faraday.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| spec.homepage = 'https://lostisland.github.io/faraday' spec.licenses = ['MIT'] - spec.required_ruby_version = '>= 2.6' + spec.required_ruby_version = '>= 3.0' # faraday-net_http is the "default adapter", but being a Faraday dependency it can't # control which version of faraday it will be pulled from. From 0ccb6c62cb6d3b2c03f8440bbeadcd433aa5d45c Mon Sep 17 00:00:00 2001 From: Mattia Giuffrida Date: Wed, 27 Dec 2023 10:36:49 +0000 Subject: [PATCH 2/6] Remove `ruby2_keywords` dependency --- faraday.gemspec | 1 - lib/faraday/rack_builder.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/faraday.gemspec b/faraday.gemspec index ed9b4ab18..0f036247f 100644 --- a/faraday.gemspec +++ b/faraday.gemspec @@ -22,7 +22,6 @@ Gem::Specification.new do |spec| # This way, we can release minor versions of the adapter with "breaking" changes for older versions of Faraday # and then bump the version requirement on the next compatible version of faraday. spec.add_dependency 'faraday-net_http', '>= 2.0', '< 3.1' - spec.add_dependency 'ruby2_keywords', '>= 0.0.4' # Includes `examples` and `spec` to allow external adapter gems to run Faraday unit and integration tests spec.files = Dir['CHANGELOG.md', '{examples,lib,spec}/**/*', 'LICENSE.md', 'Rakefile', 'README.md'] diff --git a/lib/faraday/rack_builder.rb b/lib/faraday/rack_builder.rb index d0da5488c..e8e62082b 100644 --- a/lib/faraday/rack_builder.rb +++ b/lib/faraday/rack_builder.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'ruby2_keywords' require 'faraday/adapter_registry' module Faraday From db9c157259211aaa0bad780b35267599d3e1d0fc Mon Sep 17 00:00:00 2001 From: Mattia Giuffrida Date: Wed, 27 Dec 2023 10:37:19 +0000 Subject: [PATCH 3/6] Update GitHub workflows, add 3.3 to CI matrix --- .github/workflows/ci.yml | 7 +++---- .github/workflows/publish.yml | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3746c519..6bb08bfe2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Ruby 2.7 + - name: Set up Ruby 3.0 uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: 3.0 bundler-cache: true - name: Rubocop @@ -43,7 +43,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: [ '2.6', '2.7', '3.0', '3.1', '3.2' ] + ruby: [ '3.0', '3.1', '3.2', '3.3' ] experimental: [false] include: - ruby: head @@ -63,7 +63,6 @@ jobs: run: bundle exec rake - name: Test External Adapters - if: ${{ matrix.ruby != '2.6' }} continue-on-error: ${{ matrix.experimental }} run: bundle exec bake test:external diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9b09d65ac..16af4e3d3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,10 +14,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Ruby 2.7 + - name: Set up Ruby 3.3 uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: 3.3 - name: Publish to RubyGems uses: dawidd6/action-publish-gem@v1 From ac18b2f16a6528ec98a4b7f1b770aefe0fb9b28b Mon Sep 17 00:00:00 2001 From: Mattia Giuffrida Date: Wed, 27 Dec 2023 10:46:18 +0000 Subject: [PATCH 4/6] Fix Rubocop offenses --- .rubocop_todo.yml | 31 +++++++++++++------ lib/faraday/connection.rb | 2 +- lib/faraday/encoders/nested_params_encoder.rb | 2 +- lib/faraday/options/env.rb | 2 +- lib/faraday/request/json.rb | 2 +- lib/faraday/response/raise_error.rb | 4 +-- lib/faraday/utils.rb | 4 +-- spec/spec_helper.rb | 11 ++++--- 8 files changed, 35 insertions(+), 23 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fbec6de43..9b7e255db 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2022-08-08 14:26:32 UTC using RuboCop version 1.33.0. +# on 2023-12-27 11:12:52 UTC using RuboCop version 1.59.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 @@ -23,23 +23,23 @@ Lint/EmptyBlock: - 'spec/faraday/rack_builder_spec.rb' - 'spec/faraday/response_spec.rb' -# Offense count: 12 -# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes. +# Offense count: 13 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 42 -# Offense count: 4 +# Offense count: 3 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 230 + Max: 225 # Offense count: 9 -# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods. +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 13 -# Offense count: 26 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods. +# Offense count: 27 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 33 @@ -48,11 +48,22 @@ Metrics/MethodLength: Metrics/ParameterLists: Max: 6 -# Offense count: 6 -# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods. +# Offense count: 7 +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: Max: 14 +# Offense count: 19 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames. +# RedundantRestArgumentNames: args, arguments +# RedundantKeywordRestArgumentNames: kwargs, options, opts +# RedundantBlockArgumentNames: blk, block, proc +Style/ArgumentsForwarding: + Exclude: + - 'lib/faraday.rb' + - 'lib/faraday/rack_builder.rb' + # Offense count: 3 Style/DocumentDynamicEvalDefinition: Exclude: diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index 1984f875c..0196945ee 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -15,7 +15,7 @@ module Faraday class Connection # A Set of allowed HTTP verbs. METHODS = Set.new %i[get post put delete head patch options trace] - USER_AGENT = "Faraday v#{VERSION}" + USER_AGENT = "Faraday v#{VERSION}".freeze # @return [Hash] URI query unencoded key/value pairs. attr_reader :params diff --git a/lib/faraday/encoders/nested_params_encoder.rb b/lib/faraday/encoders/nested_params_encoder.rb index afc940acd..3ca3e73e7 100644 --- a/lib/faraday/encoders/nested_params_encoder.rb +++ b/lib/faraday/encoders/nested_params_encoder.rb @@ -102,7 +102,7 @@ def decode(query) protected - SUBKEYS_REGEX = /[^\[\]]+(?:\]?\[\])?/.freeze + SUBKEYS_REGEX = /[^\[\]]+(?:\]?\[\])?/ def decode_pair(key, value, context) subkeys = key.scan(SUBKEYS_REGEX) diff --git a/lib/faraday/options/env.rb b/lib/faraday/options/env.rb index 6e6224557..fb04b117d 100644 --- a/lib/faraday/options/env.rb +++ b/lib/faraday/options/env.rb @@ -60,7 +60,7 @@ module Faraday :reason_phrase, :response_body) do const_set(:ContentLength, 'Content-Length') const_set(:StatusesWithoutBody, Set.new([204, 304])) - const_set(:SuccessfulStatuses, (200..299).freeze) + const_set(:SuccessfulStatuses, (200..299)) # A Set of HTTP verbs that typically send a body. If no body is set for # these requests, the Content-Length header is set to 0. diff --git a/lib/faraday/request/json.rb b/lib/faraday/request/json.rb index 52e410760..f12ebe298 100644 --- a/lib/faraday/request/json.rb +++ b/lib/faraday/request/json.rb @@ -13,7 +13,7 @@ class Request # Doesn't try to encode bodies that already are in string form. class Json < Middleware MIME_TYPE = 'application/json' - MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}.freeze + MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$} def on_request(env) match_content_type(env) do |data| diff --git a/lib/faraday/response/raise_error.rb b/lib/faraday/response/raise_error.rb index f2c5aec4f..76de80bb6 100644 --- a/lib/faraday/response/raise_error.rb +++ b/lib/faraday/response/raise_error.rb @@ -6,8 +6,8 @@ class Response # client or server error responses. class RaiseError < Middleware # rubocop:disable Naming/ConstantName - ClientErrorStatuses = (400...500).freeze - ServerErrorStatuses = (500...600).freeze + ClientErrorStatuses = (400...500) + ServerErrorStatuses = (500...600) # rubocop:enable Naming/ConstantName def on_complete(env) diff --git a/lib/faraday/utils.rb b/lib/faraday/utils.rb index c3368216c..809b3a88e 100644 --- a/lib/faraday/utils.rb +++ b/lib/faraday/utils.rb @@ -25,7 +25,7 @@ class << self attr_writer :default_space_encoding end - ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/.freeze + ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/ def escape(str) str.to_s.gsub(ESCAPE_RE) do |match| @@ -37,7 +37,7 @@ def unescape(str) CGI.unescape str.to_s end - DEFAULT_SEP = /[&;] */n.freeze + DEFAULT_SEP = /[&;] */n # Adapted from Rack def parse_query(query) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5fcddd5b0..1b80ea248 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,14 +29,15 @@ minimum_coverage_by_file 26 end -# Ensure all /lib files are loaded -# so they will be included in the test coverage report. -Dir['./lib/**/*.rb'].sort.each { |file| require file } - require 'faraday' require 'pry' -Dir['./spec/support/**/*.rb'].sort.each { |f| require f } +# Ensure all /lib files are loaded +# so they will be included in the test coverage report. +Dir['./lib/**/*.rb'].each { |file| require file } + +# Load all Rspec support files +Dir['./spec/support/**/*.rb'].each { |file| require file } RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate From 15cfb2e5ff4752ef522fe934cde186effe950ab2 Mon Sep 17 00:00:00 2001 From: Mattia Giuffrida Date: Thu, 28 Dec 2023 12:20:29 +0000 Subject: [PATCH 5/6] Run rubocop in CI using Ruby 3.3 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bb08bfe2..e611f8ef8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Ruby 3.0 + - name: Set up Ruby 3.3 uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0 + ruby-version: 3.3 bundler-cache: true - name: Rubocop From 2bfeb852df23d23944ce0c00ce72d757843dae89 Mon Sep 17 00:00:00 2001 From: Mattia Giuffrida Date: Thu, 28 Dec 2023 12:37:06 +0000 Subject: [PATCH 6/6] Use latest Ruby version to publish and run rubocop --- .github/workflows/ci.yml | 4 ++-- .github/workflows/publish.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e611f8ef8..fbe375628 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Ruby 3.3 + - name: Setup Ruby 3.x uses: ruby/setup-ruby@v1 with: - ruby-version: 3.3 + ruby-version: 3 bundler-cache: true - name: Rubocop diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 16af4e3d3..324e25bfa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,10 +14,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Ruby 3.3 + - name: Setup Ruby 3.x uses: ruby/setup-ruby@v1 with: - ruby-version: 3.3 + ruby-version: 3 - name: Publish to RubyGems uses: dawidd6/action-publish-gem@v1