Autocorrect Style/HashEachMethods offenses

This commit is contained in:
Carlos Chitty
2025-04-29 14:31:50 -04:00
parent 446be6e127
commit d0c687650e
10 changed files with 13 additions and 29 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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'])

View File

@@ -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)

View File

@@ -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

View File

@@ -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?

View File

@@ -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

View File

@@ -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 != '')

View File

@@ -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