Safely autocorrect Lint/SafeNavigationChain

Inspecting 1480 files
........................................................................................................................................................................................................................................................................................................................................W............................W..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Offenses:

app/models/spree/line_item.rb:283:55: W: [Corrected] Lint/SafeNavigationChain: Do not chain ordinary method call after safe navigation operator.
        self.final_weight_volume = variant&.unit_value * quantity
                                                      ^^^^^^^^^^^
app/models/spree/line_item.rb:283:57: C: [Corrected] Layout/SpaceAroundMethodCallOperator: Avoid using spaces around a method call operator.
        self.final_weight_volume = variant&.unit_value&. * quantity
                                                        ^
app/models/spree/stock/availability_validator.rb:31:77: W: [Corrected] Lint/SafeNavigationChain: Do not chain ordinary method call after safe navigation operator.
        return line_item.order.shipments.first if line_item.order&.shipments.any?
                                                                            ^^^^^

1480 files inspected, 3 offenses detected, 3 offenses corrected
This commit is contained in:
Neal Chambers
2023-07-28 16:39:43 +09:00
parent e7d53753e4
commit 2a76b1972f
3 changed files with 2 additions and 11 deletions

View File

@@ -141,15 +141,6 @@ Lint/RedundantSafeNavigation:
Exclude:
- 'app/models/spree/payment.rb'
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedMethods.
# AllowedMethods: present?, blank?, presence, try, try!, in?
Lint/SafeNavigationChain:
Exclude:
- 'app/models/spree/line_item.rb'
- 'app/models/spree/stock/availability_validator.rb'
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.

View File

@@ -280,7 +280,7 @@ module Spree
if final_weight_volume.present? && quantity_was > 0
self.final_weight_volume = final_weight_volume * quantity / quantity_was
elsif variant&.unit_value.present?
self.final_weight_volume = variant&.unit_value * quantity
self.final_weight_volume = variant&.unit_value&.* quantity
end
end
end

View File

@@ -28,7 +28,7 @@ module Spree
def line_item_shipment(line_item)
return line_item.target_shipment if line_item.target_shipment
return line_item.order.shipments.first if line_item.order&.shipments.any?
return line_item.order.shipments.first if line_item.order&.shipments&.any?
end
# Overrides Spree v2.0.4 validate method version to: