From 5618369f790cb4cd255bfe02a0fa898a9424d924 Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Sat, 15 Nov 2025 18:42:27 +0100 Subject: [PATCH] Update RuboCop to 1.81.7 and fix style offenses --- .rubocop_todo.yml | 24 ++++++++----------- CHANGELOG.md | 1 + Gemfile | 6 ++--- lib/grape/api.rb | 1 + lib/grape/api/instance.rb | 1 + lib/grape/middleware/stack.rb | 1 + lib/grape/util/cache.rb | 1 + .../grape/api/deeply_included_options_spec.rb | 1 + spec/grape/api/nested_helpers_spec.rb | 1 + spec/grape/api_spec.rb | 1 + spec/grape/dsl/parameters_spec.rb | 1 + .../validations/params_documentation_spec.rb | 1 + spec/grape/validations/params_scope_spec.rb | 4 +--- spec/grape/validations_spec.rb | 1 + 14 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 53d6756ab..be6b3e5f1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-06-18 20:27:19 UTC using RuboCop version 1.76.2. +# on 2025-11-15 17:39:14 UTC using RuboCop version 1.81.7. # 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 @@ -70,6 +70,11 @@ RSpec/InstanceVariable: - 'spec/grape/middleware/versioner/accept_version_header_spec.rb' - 'spec/grape/middleware/versioner/header_spec.rb' +# Offense count: 1 +RSpec/LeakyLocalVariable: + Exclude: + - 'spec/grape/api_spec.rb' + # Offense count: 1 RSpec/MessageChain: Exclude: @@ -94,39 +99,32 @@ RSpec/RepeatedExample: - 'spec/grape/middleware/versioner/accept_version_header_spec.rb' - 'spec/grape/validations/validators/allow_blank_validator_spec.rb' -# Offense count: 10 +# Offense count: 8 RSpec/RepeatedExampleGroupDescription: Exclude: - 'spec/grape/api_spec.rb' - 'spec/grape/endpoint_spec.rb' - 'spec/grape/util/inheritable_setting_spec.rb' - - 'spec/grape/validations/validators/values_validator_spec.rb' -# Offense count: 4 +# Offense count: 2 RSpec/StubbedMock: Exclude: - 'spec/grape/dsl/inside_route_spec.rb' - - 'spec/grape/dsl/routing_spec.rb' - 'spec/grape/middleware/formatter_spec.rb' -# Offense count: 118 +# Offense count: 32 RSpec/SubjectStub: Exclude: - 'spec/grape/api_spec.rb' - - 'spec/grape/dsl/callbacks_spec.rb' - - 'spec/grape/dsl/helpers_spec.rb' - 'spec/grape/dsl/inside_route_spec.rb' - - 'spec/grape/dsl/middleware_spec.rb' - 'spec/grape/dsl/parameters_spec.rb' - - 'spec/grape/dsl/request_response_spec.rb' - 'spec/grape/dsl/routing_spec.rb' - - 'spec/grape/dsl/settings_spec.rb' - 'spec/grape/middleware/base_spec.rb' - 'spec/grape/middleware/formatter_spec.rb' - 'spec/grape/middleware/globals_spec.rb' - 'spec/grape/middleware/stack_spec.rb' -# Offense count: 22 +# Offense count: 20 # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: @@ -134,8 +132,6 @@ RSpec/VerifiedDoubles: - 'spec/grape/dsl/inside_route_spec.rb' - 'spec/grape/integration/rack_sendfile_spec.rb' - 'spec/grape/middleware/formatter_spec.rb' - - 'spec/grape/validations/multiple_attributes_iterator_spec.rb' - - 'spec/grape/validations/single_attribute_iterator_spec.rb' # Offense count: 2 RSpec/VoidExpect: diff --git a/CHANGELOG.md b/CHANGELOG.md index d10ed6c57..fdf7b7821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ #### Features +* [#2625](https://github.com/ruby-grape/grape/pull/2625): Update rubocop to 1.81.7 and fix style offenses - [@ericproulx](https://github.com/ericproulx). * Your contribution here. #### Fixes diff --git a/Gemfile b/Gemfile index 5f4657906..499ba56eb 100644 --- a/Gemfile +++ b/Gemfile @@ -8,9 +8,9 @@ group :development, :test do gem 'builder', require: false gem 'bundler' gem 'rake' - gem 'rubocop', '1.76.2', require: false - gem 'rubocop-performance', '1.25.0', require: false - gem 'rubocop-rspec', '3.6.0', require: false + gem 'rubocop', '1.81.7', require: false + gem 'rubocop-performance', '1.26.1', require: false + gem 'rubocop-rspec', '3.8.0', require: false end group :development do diff --git a/lib/grape/api.rb b/lib/grape/api.rb index 17a998861..540d70542 100644 --- a/lib/grape/api.rb +++ b/lib/grape/api.rb @@ -19,6 +19,7 @@ def self.build(val) class << self extend Forwardable + attr_accessor :base_instance, :instances delegate_missing_to :base_instance diff --git a/lib/grape/api/instance.rb b/lib/grape/api/instance.rb index be79d45b5..8fb764eb0 100644 --- a/lib/grape/api/instance.rb +++ b/lib/grape/api/instance.rb @@ -20,6 +20,7 @@ class Instance class << self extend Forwardable + attr_reader :instance, :base attr_accessor :configuration diff --git a/lib/grape/middleware/stack.rb b/lib/grape/middleware/stack.rb index cfcb034e6..6d6bbcf1b 100644 --- a/lib/grape/middleware/stack.rb +++ b/lib/grape/middleware/stack.rb @@ -6,6 +6,7 @@ module Middleware # It allows to insert and insert after class Stack extend Forwardable + class Middleware attr_reader :args, :block, :klass diff --git a/lib/grape/util/cache.rb b/lib/grape/util/cache.rb index 7514296c2..5654cce34 100644 --- a/lib/grape/util/cache.rb +++ b/lib/grape/util/cache.rb @@ -9,6 +9,7 @@ class Cache class << self extend Forwardable + def_delegators :cache, :[] def_delegators :instance, :cache end diff --git a/spec/grape/api/deeply_included_options_spec.rb b/spec/grape/api/deeply_included_options_spec.rb index 940e11560..ecc72b7f5 100644 --- a/spec/grape/api/deeply_included_options_spec.rb +++ b/spec/grape/api/deeply_included_options_spec.rb @@ -32,6 +32,7 @@ let(:default) do Module.new do extend ActiveSupport::Concern + included do format :json end diff --git a/spec/grape/api/nested_helpers_spec.rb b/spec/grape/api/nested_helpers_spec.rb index 77975f434..d09e9819e 100644 --- a/spec/grape/api/nested_helpers_spec.rb +++ b/spec/grape/api/nested_helpers_spec.rb @@ -4,6 +4,7 @@ let(:helper_methods) do Module.new do extend Grape::API::Helpers + def current_user @current_user ||= params[:current_user] end diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 578e27a96..03aeaefce 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -3909,6 +3909,7 @@ def my_method v1 = Class.new(described_class) do version :v1, using: :path include module_to_include + my_method end v2 = Class.new(described_class) do diff --git a/spec/grape/dsl/parameters_spec.rb b/spec/grape/dsl/parameters_spec.rb index cd1795b39..0059929d5 100644 --- a/spec/grape/dsl/parameters_spec.rb +++ b/spec/grape/dsl/parameters_spec.rb @@ -6,6 +6,7 @@ let(:dummy_class) do Class.new do include Grape::DSL::Parameters + attr_accessor :api, :element, :parent def initialize diff --git a/spec/grape/validations/params_documentation_spec.rb b/spec/grape/validations/params_documentation_spec.rb index 4952db9a2..a88b171f5 100644 --- a/spec/grape/validations/params_documentation_spec.rb +++ b/spec/grape/validations/params_documentation_spec.rb @@ -12,6 +12,7 @@ let(:klass) do Class.new do include Grape::Validations::ParamsDocumentation + attr_accessor :api def initialize(api) diff --git a/spec/grape/validations/params_scope_spec.rb b/spec/grape/validations/params_scope_spec.rb index 0e9443631..223fa3b13 100644 --- a/spec/grape/validations/params_scope_spec.rb +++ b/spec/grape/validations/params_scope_spec.rb @@ -1242,9 +1242,7 @@ def initialize(value) a_options = [{}, { values: %w[x y z] }] b_options = [{}, { type: String }, { allow_blank: false }, { type: String, allow_blank: false }] combinations = a_decls.product(a_options, b_options) - combinations.each_with_index do |combination, i| - a_decl, a_opts, b_opts = combination - + combinations.each_with_index do |(a_decl, a_opts, b_opts), i| context "(case #{i})" do before do # puts "a_decl: #{a_decl}, a_opts: #{a_opts}, b_opts: #{b_opts}" diff --git a/spec/grape/validations_spec.rb b/spec/grape/validations_spec.rb index ae5b27a23..57db56764 100644 --- a/spec/grape/validations_spec.rb +++ b/spec/grape/validations_spec.rb @@ -1381,6 +1381,7 @@ def validate_param!(attr_name, params) before do shared_params = Module.new do extend Grape::DSL::Helpers::BaseHelper + params :period do optional :start_date optional :end_date