Correct Style/ReturnNilInPredicateMethodDefinition rubocop offenses

Explicitly return false instead of nil
This commit is contained in:
Carlos Chitty
2025-05-26 13:30:13 -04:00
parent a1e0feef14
commit 00aa60c8a3
4 changed files with 19 additions and 28 deletions

View File

@@ -326,12 +326,3 @@ Style/OptionalBooleanParameter:
- 'engines/order_management/app/services/order_management/stock/estimator.rb'
- 'lib/spree/core/controller_helpers/order.rb'
- 'spec/support/request/web_helper.rb'
# Offense count: 19
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods, AllowedPatterns.
Style/ReturnNilInPredicateMethodDefinition:
Exclude:
- 'app/models/order_cycle.rb'
- 'app/serializers/api/admin/customer_serializer.rb'
- 'engines/order_management/app/services/order_management/subscriptions/validator.rb'

View File

@@ -345,8 +345,8 @@ class OrderCycle < ApplicationRecord
end
def orders_close_at_after_orders_open_at?
return if orders_open_at.blank? || orders_close_at.blank?
return if orders_close_at > orders_open_at
return false if orders_open_at.blank? || orders_close_at.blank?
return false if orders_close_at > orders_open_at
errors.add(:orders_close_at, :after_orders_open_at)
end

View File

@@ -25,7 +25,7 @@ module Api
end
def default_card_present?
return unless object.user
return false unless object.user
object.user.default_card.present?
end

View File

@@ -41,53 +41,53 @@ module OrderManagement
private
def shipping_method_allowed?
return unless shipping_method
return if shipping_method.distributors.include?(shop)
return false unless shipping_method
return false if shipping_method.distributors.include?(shop)
errors.add(:shipping_method, :not_available_to_shop, shop: shop.name)
end
def payment_method_allowed?
return unless payment_method
return if payment_method.distributors.include?(shop)
return false unless payment_method
return false if payment_method.distributors.include?(shop)
errors.add(:payment_method, :not_available_to_shop, shop: shop.name)
end
def payment_method_type_allowed?
return unless payment_method
return if Subscription::ALLOWED_PAYMENT_METHOD_TYPES.include? payment_method.type
return false unless payment_method
return false if Subscription::ALLOWED_PAYMENT_METHOD_TYPES.include? payment_method.type
errors.add(:payment_method, :invalid_type)
end
def ends_at_after_begins_at?
# Only validates ends_at if it is present
return if begins_at.blank? || ends_at.blank?
return if ends_at > begins_at
return false if begins_at.blank? || ends_at.blank?
return false if ends_at > begins_at
errors.add(:ends_at, :after_begins_at)
end
def customer_allowed?
return unless customer
return if customer.enterprise == shop
return false unless customer
return false if customer.enterprise == shop
errors.add(:customer, :does_not_belong_to_shop, shop: shop.name)
end
def schedule_allowed?
return unless schedule
return if schedule.coordinators.include?(shop)
return false unless schedule
return false if schedule.coordinators.include?(shop)
errors.add(:schedule, :not_coordinated_by_shop, shop: shop.name)
end
def credit_card_ok?
return unless customer && payment_method
return unless stripe_payment_method?(payment_method)
return false unless customer && payment_method
return false unless stripe_payment_method?(payment_method)
return errors.add(:payment_method, :charges_not_allowed) unless customer.allow_charges
return if customer.user&.default_card.present?
return false if customer.user&.default_card.present?
errors.add(:payment_method, :no_default_card)
end
@@ -97,7 +97,7 @@ module OrderManagement
end
def subscription_line_items_present?
return if subscription_line_items.any? { |sli|
return false if subscription_line_items.any? { |sli|
sli.quantity > 0 && !sli.marked_for_destruction?
}