Merge pull request #11533 from macanudo527/fix_stylehash_2

Fix Style/HashSyntax 3/13
This commit is contained in:
Maikel
2023-09-14 09:04:03 +10:00
committed by GitHub
31 changed files with 85 additions and 115 deletions

View File

@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp`
# using RuboCop version 1.56.2.
# using RuboCop version 1.56.3.
# 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
@@ -772,7 +772,7 @@ Security/Open:
Exclude:
- 'app/services/image_importer.rb'
# Offense count: 11
# Offense count: 9
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ArrayIntersect:
Exclude:
@@ -875,43 +875,13 @@ Style/HashLikeCase:
Exclude:
- 'app/models/enterprise.rb'
# Offense count: 1715
# Offense count: 1563
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
# SupportedShorthandSyntax: always, never, either, consistent
Style/HashSyntax:
Exclude:
- 'app/models/spree/adjustment.rb'
- 'app/models/spree/credit_card.rb'
- 'app/models/spree/gateway/pay_pal_express.rb'
- 'app/models/spree/gateway/stripe_sca.rb'
- 'app/models/spree/inventory_unit.rb'
- 'app/models/spree/item_adjustments.rb'
- 'app/models/spree/line_item.rb'
- 'app/models/spree/order.rb'
- 'app/models/spree/order/checkout.rb'
- 'app/models/spree/order_contents.rb'
- 'app/models/spree/payment.rb'
- 'app/models/spree/payment/processing.rb'
- 'app/models/spree/preferences/store.rb'
- 'app/models/spree/price.rb'
- 'app/models/spree/product.rb'
- 'app/models/spree/product_property.rb'
- 'app/models/spree/return_authorization.rb'
- 'app/models/spree/shipment.rb'
- 'app/models/spree/shipping_rate.rb'
- 'app/models/spree/stock_location.rb'
- 'app/models/spree/tax_rate.rb'
- 'app/models/spree/taxonomy.rb'
- 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
- 'app/models/stripe_account.rb'
- 'app/models/voucher.rb'
- 'app/reflexes/admin/orders_reflex.rb'
- 'app/reflexes/invite_manager_reflex.rb'
- 'app/reflexes/white_label_reflex.rb'
- 'app/serializers/api/admin/enterprise_serializer.rb'
- 'app/services/address_geocoder.rb'
- 'app/services/customer_syncer.rb'
- 'app/services/exchange_variant_bulk_updater.rb'

View File

@@ -109,7 +109,7 @@ module Spree
if originator.present?
amount = originator.compute_amount(calculable || adjustable)
update_columns(
amount: amount,
amount:,
updated_at: Time.zone.now,
)
end
@@ -122,7 +122,7 @@ module Spree
end
def display_amount
Spree::Money.new(amount, currency: currency)
Spree::Money.new(amount, currency:)
end
def admin?

View File

@@ -102,12 +102,12 @@ module Spree
def to_active_merchant
ActiveMerchant::Billing::CreditCard.new(
number: number,
month: month,
year: year,
verification_value: verification_value,
first_name: first_name,
last_name: last_name
number:,
month:,
year:,
verification_value:,
first_name:,
last_name:
)
end

View File

@@ -100,7 +100,7 @@ module Spree
refunded_at: Time.now,
refund_transaction_id: refund_transaction_response.RefundTransactionID,
state: "refunded",
refund_type: refund_type
refund_type:
)
payment.class.create!(

View File

@@ -69,7 +69,7 @@ module Spree
customer, payment_method =
Stripe::CreditCardCloner.new(creditcard, stripe_account_id).find_or_clone
options = basic_options(gateway_options).merge(customer: customer, off_session: true)
options = basic_options(gateway_options).merge(customer:, off_session: true)
provider.purchase(money, payment_method, options)
rescue Stripe::StripeError => e
failed_activemerchant_billing_response(e.message)
@@ -164,7 +164,7 @@ module Spree
state = payment_intent_response.status
return if state == 'requires_capture'
raise Stripe::StripeError, I18n.t(:invalid_payment_state, state: state)
raise Stripe::StripeError, I18n.t(:invalid_payment_state, state:)
end
def fetch_payment(creditcard, gateway_options)

View File

@@ -58,7 +58,7 @@ module Spree
def find_stock_item
Spree::StockItem.find_by(stock_location_id: shipment.stock_location_id,
variant_id: variant_id)
variant_id:)
end
private

View File

@@ -22,9 +22,9 @@ module Spree
additional_tax_total = tax_adjustments.additional.reload.map(&:update_adjustment!).compact.sum
item.update_columns(
included_tax_total: included_tax_total,
additional_tax_total: additional_tax_total,
adjustment_total: adjustment_total,
included_tax_total:,
additional_tax_total:,
adjustment_total:,
updated_at: Time.zone.now
)
end

View File

@@ -142,12 +142,12 @@ module Spree
alias total amount
def single_money
Spree::Money.new(price, currency: currency)
Spree::Money.new(price, currency:)
end
alias single_display_amount single_money
def money
Spree::Money.new(amount, currency: currency)
Spree::Money.new(amount, currency:)
end
alias display_total money
alias display_amount money
@@ -209,7 +209,7 @@ module Spree
end
def single_display_amount_with_adjustments
Spree::Money.new(price_with_adjustments, currency: currency)
Spree::Money.new(price_with_adjustments, currency:)
end
def amount_with_adjustments
@@ -219,11 +219,11 @@ module Spree
end
def display_amount_with_adjustments
Spree::Money.new(amount_with_adjustments, currency: currency)
Spree::Money.new(amount_with_adjustments, currency:)
end
def display_included_tax
Spree::Money.new(included_tax, currency: currency)
Spree::Money.new(included_tax, currency:)
end
def unit_value

View File

@@ -168,8 +168,8 @@ module Spree
scope :finalized, -> { where(state: FINALIZED_STATES) }
scope :complete, -> { where.not(completed_at: nil) }
scope :incomplete, -> { where(completed_at: nil) }
scope :by_state, lambda { |state| where(state: state) }
scope :not_state, lambda { |state| where.not(state: state) }
scope :by_state, lambda { |state| where(state:) }
scope :not_state, lambda { |state| where.not(state:) }
def initialize(*_args)
@checkout_processing = nil
@@ -193,15 +193,15 @@ module Spree
end
def display_item_total
Spree::Money.new(item_total, currency: currency)
Spree::Money.new(item_total, currency:)
end
def display_adjustment_total
Spree::Money.new(adjustment_total, currency: currency)
Spree::Money.new(adjustment_total, currency:)
end
def display_total
Spree::Money.new(total, currency: currency)
Spree::Money.new(total, currency:)
end
def to_param
@@ -312,9 +312,9 @@ module Spree
# Persist the changes we just made,
# but don't use save since we might have an invalid address associated
self.class.unscoped.where(id: id).update_all(email: user.email,
user_id: user.id,
created_by_id: created_by_id)
self.class.unscoped.where(id:).update_all(email: user.email,
user_id: user.id,
created_by_id:)
end
def generate_order_number
@@ -393,7 +393,7 @@ module Spree
previous_state: 'cart',
next_state: 'complete',
name: 'order',
user_id: user_id
user_id:
)
end
@@ -673,7 +673,7 @@ module Spree
end
def registered_email?
Spree::User.exists?(email: email)
Spree::User.exists?(email:)
end
def adjustments_fetcher

View File

@@ -145,8 +145,8 @@ module Spree
state_changes.create(
previous_state: old_state,
next_state: __send__(state),
name: name,
user_id: user_id
name:,
user_id:
)
end

View File

@@ -88,7 +88,7 @@ module Spree
line_item.target_shipment = shipment
line_item.quantity += quantity.to_i
else
line_item = order.line_items.new(quantity: quantity, variant: variant)
line_item = order.line_items.new(quantity:, variant:)
line_item.target_shipment = shipment
line_item.price = variant.price
end

View File

@@ -102,7 +102,7 @@ module Spree
end
def money
Spree::Money.new(amount, currency: currency)
Spree::Money.new(amount, currency:)
end
alias display_amount money
@@ -220,7 +220,7 @@ module Spree
# Makes newly entered payments invalidate previously entered payments so the most recent payment
# is used by the gateway.
def invalidate_old_payments
order.payments.incomplete.where.not(id: id).each do |payment|
order.payments.incomplete.where.not(id:).each do |payment|
# Using update_column skips validations and so it skips validate_source. As we are just
# invalidating past payments here, we don't want to validate all of them at this stage.
payment.update_columns(
@@ -245,7 +245,7 @@ module Spree
# and this is it. Related to #1998.
# See https://github.com/spree/spree/issues/1998#issuecomment-12869105
def set_unique_identifier
self.identifier = generate_identifier while self.class.exists?(identifier: identifier)
self.identifier = generate_identifier while self.class.exists?(identifier:)
end
def generate_identifier

View File

@@ -22,7 +22,7 @@ module Spree
def authorize!(return_url = nil)
started_processing!
gateway_action(source, :authorize, :pend, return_url: return_url)
gateway_action(source, :authorize, :pend, return_url:)
end
def purchase!
@@ -100,9 +100,9 @@ module Spree
if response.success?
self.class.create!(
order: order,
order:,
source: self,
payment_method: payment_method,
payment_method:,
amount: credit_amount.abs * -1,
response_code: response.authorization,
state: 'completed',
@@ -139,9 +139,9 @@ module Spree
if response.success?
self.class.create!(
order: order,
order:,
source: self,
payment_method: payment_method,
payment_method:,
amount: refund_amount.abs * -1,
response_code: response.authorization,
state: 'completed',
@@ -174,7 +174,7 @@ module Spree
tax: order.additional_tax_total * 100,
subtotal: order.item_total * 100,
discount: 0,
currency: currency)
currency:)
options.merge!({ billing_address: order.bill_address.try(:active_merchant_hash),
shipping_address: order.ship_address.try(:active_merchant_hash) })

View File

@@ -25,7 +25,7 @@ module Spree
def exist?(key)
@cache.exist?(key) ||
(should_persist? && Spree::Preference.where(key: key).exists?)
(should_persist? && Spree::Preference.where(key:).exists?)
end
def get(key, fallback = nil)
@@ -39,7 +39,7 @@ module Spree
# If it's not in the cache, maybe it's in the database, but has been cleared from the cache
# does it exist in the database?
if should_persist? && Spree::Preference.table_exists?
preference = Spree::Preference.find_by(key: key)
preference = Spree::Preference.find_by(key:)
if preference
# it does exist, so let's put it back into the cache
@cache.write(preference.key, preference.value)

View File

@@ -17,7 +17,7 @@ module Spree
alias :display_price :display_amount
def money
Spree::Money.new(amount || 0, currency: currency)
Spree::Money.new(amount || 0, currency:)
end
def price

View File

@@ -220,7 +220,7 @@ module Spree
ActiveRecord::Base.transaction do
property = Property.where(name: property_name).first_or_create!(presentation: property_name)
product_property = ProductProperty.where(product: self,
property: property).first_or_initialize
property:).first_or_initialize
product_property.value = property_value
product_property.save!
end

View File

@@ -20,8 +20,8 @@ module Spree
def property_name=(name)
return if name.blank?
unless property = Property.find_by(name: name)
property = Property.create(name: name, presentation: name)
unless property = Property.find_by(name:)
property = Property.create(name:, presentation: name)
end
self.property = property
end

View File

@@ -33,7 +33,7 @@ module Spree
end
def display_amount
Spree::Money.new(amount, currency: currency)
Spree::Money.new(amount, currency:)
end
def add_variant(variant_id, quantity)
@@ -101,7 +101,7 @@ module Spree
Adjustment.create(
amount: -amount.abs,
label: I18n.t('spree.rma_credit'),
order: order,
order:,
adjustable: order,
originator: self
)

View File

@@ -92,7 +92,7 @@ module Spree
end
def add_shipping_method(shipping_method, selected = false)
shipping_rates.create(shipping_method: shipping_method, selected: selected)
shipping_rates.create(shipping_method:, selected:)
end
def selected_shipping_rate
@@ -127,7 +127,7 @@ module Spree
.exclude?(original_shipping_method_id)
cost = estimator.calculate_cost(shipping_method, to_package)
unless cost.nil?
original_shipping_rate = shipping_method.shipping_rates.new(cost: cost)
original_shipping_rate = shipping_method.shipping_rates.new(cost:)
self.shipping_rates = distributor_shipping_rates + [original_shipping_rate]
self.selected_shipping_rate_id = original_shipping_rate.id
end
@@ -167,7 +167,7 @@ module Spree
end
def display_cost
Spree::Money.new(cost, currency: currency)
Spree::Money.new(cost, currency:)
end
alias_method :display_amount, :display_cost
@@ -177,7 +177,7 @@ module Spree
end
def display_item_cost
Spree::Money.new(item_cost, currency: currency)
Spree::Money.new(item_cost, currency:)
end
def update_amounts
@@ -195,7 +195,7 @@ module Spree
states = {}
units.group_by(&:state).each { |state, iu| states[state] = iu.count }
scoper.scope(variant)
OpenStruct.new(variant: variant, quantity: units.length, states: states)
OpenStruct.new(variant:, quantity: units.length, states:)
end
end
@@ -268,7 +268,7 @@ module Spree
end
def set_up_inventory(state, variant, order)
inventory_units.create(variant_id: variant.id, state: state, order_id: order.id)
inventory_units.create(variant_id: variant.id, state:, order_id: order.id)
end
def fee_adjustment
@@ -361,7 +361,7 @@ module Spree
def send_shipped_email
delivery = !!shipping_method.require_ship_address
ShipmentMailer.shipped_email(id, delivery: delivery).deliver_later
ShipmentMailer.shipped_email(id, delivery:).deliver_later
end
def update_adjustments

View File

@@ -19,7 +19,7 @@ module Spree
delegate :name, to: :shipping_method
def display_price
Spree::Money.new(cost, { currency: currency })
Spree::Money.new(cost, { currency: })
end
alias_method :display_cost, :display_price

View File

@@ -18,7 +18,7 @@ module Spree
# Wrapper for creating a new stock item respecting the backorderable config
def propagate_variant(variant)
stock_items.create!(variant: variant, backorderable: backorderable_default)
stock_items.create!(variant:, backorderable: backorderable_default)
end
def stock_item(variant)
@@ -26,7 +26,7 @@ module Spree
end
def stock_item_or_create(variant)
stock_item(variant) || stock_items.create(variant: variant)
stock_item(variant) || stock_items.create(variant:)
end
def count_on_hand(variant)

View File

@@ -95,10 +95,10 @@ module Spree
adjustments.create!(
adjustable: item,
amount: amount,
order: order,
amount:,
order:,
label: create_label(amount),
included: included
included:
)
end

View File

@@ -16,11 +16,11 @@ module Spree
def set_name
if root
root.update_columns(
name: name,
name:,
updated_at: Time.zone.now
)
else
self.root = Taxon.create!(taxonomy_id: id, name: name)
self.root = Taxon.create!(taxonomy_id: id, name:)
end
end
end

View File

@@ -106,7 +106,7 @@ module Spree
def build_enterprise_roles
Enterprise.all.find_each do |enterprise|
unless enterprise_roles.find_by enterprise_id: enterprise.id
enterprise_roles.build(enterprise: enterprise)
enterprise_roles.build(enterprise:)
end
end
end
@@ -130,7 +130,7 @@ module Spree
end
def associate_customers
self.customers = Customer.where(email: email)
self.customers = Customer.where(email:)
end
def associate_orders
@@ -190,8 +190,8 @@ module Spree
return unless owned_enterprises.size > enterprise_limit
errors.add(:owned_enterprises, I18n.t(:spree_user_enterprise_limit_error,
email: email,
enterprise_limit: enterprise_limit))
email:,
enterprise_limit:))
end
def remove_payments_in_checkout(enterprises)

View File

@@ -193,7 +193,7 @@ module Spree
def price_in(currency)
prices.select{ |price| price.currency == currency }.first ||
Spree::Price.new(variant_id: id, currency: currency)
Spree::Price.new(variant_id: id, currency:)
end
def amount_in(currency)

View File

@@ -8,17 +8,17 @@ class StripeAccount < ApplicationRecord
validates :enterprise_id, uniqueness: true
def deauthorize_and_destroy
accounts = StripeAccount.where(stripe_user_id: stripe_user_id)
accounts = StripeAccount.where(stripe_user_id:)
# Only deauthorize the user if it is not linked to multiple accounts
return destroy if accounts.count > 1
destroy && Stripe::OAuth.deauthorize(stripe_user_id: stripe_user_id)
destroy && Stripe::OAuth.deauthorize(stripe_user_id:)
rescue Stripe::OAuth::OAuthError
Bugsnag.notify(
RuntimeError.new("StripeDeauthorizeFailure"),
stripe_account: stripe_user_id,
enterprise_id: enterprise_id
enterprise_id:
)
true
end

View File

@@ -30,8 +30,8 @@ class Voucher < ApplicationRecord
adjustment_attributes = {
amount: 0,
originator: self,
order: order,
label: label,
order:,
label:,
mandatory: false,
state: "open",
tax_category: nil

View File

@@ -51,7 +51,7 @@ module Admin
cancelled_orders.each do |order|
cable_ready.replace(
selector: dom_id(order),
html: render(partial: "spree/admin/orders/table_row", locals: { order: order })
html: render(partial: "spree/admin/orders/table_row", locals: { order: })
)
end
@@ -89,7 +89,7 @@ module Admin
end
def success(i18n_key, count)
flash[:success] = with_locale { I18n.t(i18n_key, count: count) }
flash[:success] = with_locale { I18n.t(i18n_key, count:) }
cable_ready.dispatch_event(name: "modal:close")
morph_admin_flashes
end

View File

@@ -9,9 +9,9 @@ class InviteManagerReflex < ApplicationReflex
authorize! :edit, enterprise
existing_user = Spree::User.find_by(email: email)
existing_user = Spree::User.find_by(email:)
locals = { error: nil, success: nil, email: email, enterprise: enterprise }
locals = { error: nil, success: nil, email:, enterprise: }
if existing_user
locals[:error] = I18n.t('admin.enterprises.invite_manager.user_already_exists')
@@ -36,7 +36,7 @@ class InviteManagerReflex < ApplicationReflex
def return_morph(locals)
morph "#add_manager_modal",
with_locale {
render(partial: "admin/enterprises/form/add_new_unregistered_manager", locals: locals)
render(partial: "admin/enterprises/form/add_new_unregistered_manager", locals:)
}
end
end

View File

@@ -13,7 +13,7 @@ class WhiteLabelReflex < ApplicationReflex
html = with_locale {
render(partial: "admin/enterprises/form/white_label",
locals: { f: f, enterprise: @enterprise })
locals: { f:, enterprise: @enterprise })
}
morph "#white_label_panel", html

View File

@@ -75,7 +75,7 @@ module Api
return tag_group if tag_group[:tags].length == tags.length &&
(tag_group[:tags] & tags) == tag_group[:tags]
end
{ tags: tags, rules: [] }
{ tags:, rules: [] }
end
private