From 00aa60c8a3d60093d6e0add1735d674ac9faad00 Mon Sep 17 00:00:00 2001 From: Carlos Chitty Date: Mon, 26 May 2025 13:30:13 -0400 Subject: [PATCH] Correct Style/ReturnNilInPredicateMethodDefinition rubocop offenses Explicitly return false instead of nil --- .rubocop_todo.yml | 9 ------ app/models/order_cycle.rb | 4 +-- .../api/admin/customer_serializer.rb | 2 +- .../subscriptions/validator.rb | 32 +++++++++---------- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f778f90e75..63d8cd630c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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' diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 82d060200b..06bc7f2b5b 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -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 diff --git a/app/serializers/api/admin/customer_serializer.rb b/app/serializers/api/admin/customer_serializer.rb index 14e8478e49..3fcd6ce24a 100644 --- a/app/serializers/api/admin/customer_serializer.rb +++ b/app/serializers/api/admin/customer_serializer.rb @@ -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 diff --git a/engines/order_management/app/services/order_management/subscriptions/validator.rb b/engines/order_management/app/services/order_management/subscriptions/validator.rb index 1dc04bfd5d..fe760cd37e 100644 --- a/engines/order_management/app/services/order_management/subscriptions/validator.rb +++ b/engines/order_management/app/services/order_management/subscriptions/validator.rb @@ -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? }