From d0c687650ef87fc3b5c91f6891b43f21a5fe55cd Mon Sep 17 00:00:00 2001 From: Carlos Chitty Date: Tue, 29 Apr 2025 14:31:50 -0400 Subject: [PATCH] Autocorrect Style/HashEachMethods offenses --- .rubocop_todo.yml | 16 ---------------- app/controllers/admin/enterprises_controller.rb | 6 +++--- .../spree/admin/shipping_methods_controller.rb | 2 +- app/forms/enterprise_fees_bulk_update.rb | 6 +++--- app/models/product_import/entry_processor.rb | 2 +- app/models/spree/preferences/configuration.rb | 2 +- app/services/sets/model_set.rb | 2 +- .../sales_tax/sales_tax_totals_by_producer.rb | 2 +- spec/models/product_importer_spec.rb | 2 +- spec/support/cancan_helper.rb | 2 +- 10 files changed, 13 insertions(+), 29 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c21ecf39d6..d631082ed8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -508,22 +508,6 @@ Style/ClassAndModuleChildren: - 'lib/open_food_network/locking.rb' - 'spec/models/spree/payment_method_spec.rb' -# Offense count: 13 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowedReceivers. -# AllowedReceivers: Thread.current -Style/HashEachMethods: - Exclude: - - 'app/controllers/admin/enterprises_controller.rb' - - 'app/controllers/spree/admin/shipping_methods_controller.rb' - - 'app/forms/enterprise_fees_bulk_update.rb' - - 'app/models/product_import/entry_processor.rb' - - 'app/models/spree/preferences/configuration.rb' - - 'app/services/sets/model_set.rb' - - 'lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb' - - 'spec/models/product_importer_spec.rb' - - 'spec/support/cancan_helper.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). Style/MapToHash: diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 1fd7d38a90..beb3f77b82 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -254,7 +254,7 @@ module Admin # methods that are specific to each class do not become available until after the # record is persisted. This problem is compounded by the use of calculators. @object.transaction do - tag_rules_attributes.select{ |_i, attrs| attrs[:type].present? }.each do |_i, attrs| + tag_rules_attributes.select{ |_i, attrs| attrs[:type].present? }.each_value do |attrs| rule = @object.tag_rules.find_by(id: attrs.delete(:id)) || attrs[:type].constantize.new(enterprise: @object) @@ -293,7 +293,7 @@ module Admin def check_can_change_bulk_sells return if spree_current_user.admin? - params[:sets_enterprise_set][:collection_attributes].each do |_i, enterprise_params| + params[:sets_enterprise_set][:collection_attributes].each_value do |enterprise_params| unless spree_current_user == Enterprise.find_by(id: enterprise_params[:id]).owner enterprise_params.delete :sells end @@ -327,7 +327,7 @@ module Admin def check_can_change_bulk_owner return if spree_current_user.admin? - bulk_params[:collection_attributes].each do |_i, enterprise_params| + bulk_params[:collection_attributes].each_value do |enterprise_params| enterprise_params.delete :owner_id end end diff --git a/app/controllers/spree/admin/shipping_methods_controller.rb b/app/controllers/spree/admin/shipping_methods_controller.rb index 58f51ac858..25433b213f 100644 --- a/app/controllers/spree/admin/shipping_methods_controller.rb +++ b/app/controllers/spree/admin/shipping_methods_controller.rb @@ -104,7 +104,7 @@ module Spree return unless shipping_fees - shipping_fees.each do |_, shipping_amount| + shipping_fees.each_value do |shipping_amount| unless shipping_amount.nil? || Float(shipping_amount, exception: false) flash[:error] = I18n.t(:calculator_preferred_value_error) return redirect_to location_after_save diff --git a/app/forms/enterprise_fees_bulk_update.rb b/app/forms/enterprise_fees_bulk_update.rb index 09c138ab1b..a553b99954 100644 --- a/app/forms/enterprise_fees_bulk_update.rb +++ b/app/forms/enterprise_fees_bulk_update.rb @@ -30,7 +30,7 @@ class EnterpriseFeesBulkUpdate private def check_enterprise_fee_input - enterprise_fee_bulk_params['collection_attributes'].each do |_, fee_row| + enterprise_fee_bulk_params['collection_attributes'].each_value do |fee_row| enterprise_fees = fee_row['calculator_attributes']&.slice( :preferred_flat_percent, :preferred_amount, :preferred_first_item, :preferred_additional_item, @@ -40,7 +40,7 @@ class EnterpriseFeesBulkUpdate next unless enterprise_fees - enterprise_fees.each do |_, enterprise_amount| + enterprise_fees.each_value do |enterprise_amount| unless enterprise_amount.nil? || Float(enterprise_amount, exception: false) @errors.add(:base, I18n.t(:calculator_preferred_value_error)) end @@ -49,7 +49,7 @@ class EnterpriseFeesBulkUpdate end def check_calculators_compatibility_with_taxes - enterprise_fee_bulk_params['collection_attributes'].each do |_, enterprise_fee| + enterprise_fee_bulk_params['collection_attributes'].each_value do |enterprise_fee| next unless enterprise_fee['inherits_tax_category'] == "true" next unless EnterpriseFee::PER_ORDER_CALCULATORS.include?(enterprise_fee['calculator_type']) diff --git a/app/models/product_import/entry_processor.rb b/app/models/product_import/entry_processor.rb index 6393f14578..c658fdf8b1 100644 --- a/app/models/product_import/entry_processor.rb +++ b/app/models/product_import/entry_processor.rb @@ -46,7 +46,7 @@ module ProductImport end def count_existing_items - @spreadsheet_data.enterprises_index.each do |_enterprise_name, attrs| + @spreadsheet_data.enterprises_index.each_value do |attrs| enterprise_id = attrs[:id] next unless enterprise_id && permission_by_id?(enterprise_id) diff --git a/app/models/spree/preferences/configuration.rb b/app/models/spree/preferences/configuration.rb index a2997451a6..b534a31cfc 100644 --- a/app/models/spree/preferences/configuration.rb +++ b/app/models/spree/preferences/configuration.rb @@ -36,7 +36,7 @@ module Spree end def reset - preferences.each do |name, _value| + preferences.each_key do |name| set_preference name, preference_default(name) end end diff --git a/app/services/sets/model_set.rb b/app/services/sets/model_set.rb index 1db02abf92..854180ba2f 100644 --- a/app/services/sets/model_set.rb +++ b/app/services/sets/model_set.rb @@ -21,7 +21,7 @@ module Sets end def collection_attributes=(collection_attributes) - collection_attributes.each do |_k, attributes| + collection_attributes.each_value do |attributes| # attributes == {:id => 123, :next_collection_at => '...'} found_element = @collection.detect do |element| element.id.to_s == attributes[:id].to_s && !element.id.nil? diff --git a/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb b/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb index a2c00ea082..29bbe483e6 100644 --- a/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb +++ b/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb @@ -37,7 +37,7 @@ module Reporting hash[:line_item].order.distributor_id, hash[:line_item].order.order_cycle_id ] - end.each do |_, v| + end.each_value do |v| v.map!{ |item| item[:line_item] } end end diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 1d6392f7a4..839d286a7c 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -1059,7 +1059,7 @@ end def filter(type, entries) valid_count = 0 - entries.each do |_line_number, entry| + entries.each_value do |entry| validates_as = entry['validates_as'] valid_count += 1 if type == 'valid' && (validates_as != '') diff --git a/spec/support/cancan_helper.rb b/spec/support/cancan_helper.rb index 11b7723db2..74c087b306 100644 --- a/spec/support/cancan_helper.rb +++ b/spec/support/cancan_helper.rb @@ -17,7 +17,7 @@ module Spree member.merge(i => true) } end - ability_hash.each do |action, _true_or_false| + ability_hash.each_key do |action| @ability_result[action] = ability.can?(action, target) end