Merge pull request #11405 from macanudo527/fix_rubocop_rails_errors

Fix rubocop rails errors
This commit is contained in:
David Cook
2023-08-18 11:54:17 +10:00
committed by GitHub
17 changed files with 44 additions and 84 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.55.1.
# using RuboCop version 1.56.0.
# 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
@@ -45,7 +45,7 @@ Lint/DuplicateRequire:
Exclude:
- 'spec/lib/open_food_network/scope_variants_to_search_spec.rb'
# Offense count: 19
# Offense count: 18
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
@@ -184,7 +184,7 @@ Metrics/BlockNesting:
Exclude:
- 'app/models/spree/payment/processing.rb'
# Offense count: 48
# Offense count: 45
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
@@ -197,7 +197,6 @@ Metrics/ClassLength:
- 'app/controllers/api/v0/products_controller.rb'
- 'app/controllers/application_controller.rb'
- 'app/controllers/payment_gateways/paypal_controller.rb'
- 'app/controllers/split_checkout_controller.rb'
- 'app/controllers/spree/admin/orders_controller.rb'
- 'app/controllers/spree/admin/payment_methods_controller.rb'
- 'app/controllers/spree/admin/payments_controller.rb'
@@ -218,7 +217,6 @@ Metrics/ClassLength:
- 'app/models/spree/payment.rb'
- 'app/models/spree/product.rb'
- 'app/models/spree/shipment.rb'
- 'app/models/spree/shipping_method.rb'
- 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
- 'app/models/spree/zone.rb'
@@ -421,34 +419,6 @@ Rails/ActiveRecordOverride:
Exclude:
- 'app/models/spree/product.rb'
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/ApplicationController:
Exclude:
- 'engines/dfc_provider/app/controllers/dfc_provider/base_controller.rb'
# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent.
Rails/Blank:
Exclude:
- 'app/models/spree/order_contents.rb'
- 'app/services/content_sanitizer.rb'
- 'engines/order_management/app/services/order_management/stock/package.rb'
- 'lib/stripe/authorize_response_patcher.rb'
# Offense count: 17
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/CompactBlank:
Exclude:
- 'app/controllers/spree/admin/users_controller.rb'
- 'app/models/concerns/address_display.rb'
- 'app/models/spree/zone.rb'
- 'app/services/order_cycle_form.rb'
- 'lib/reporting/report_headers_builder.rb'
- 'lib/reporting/report_ruler.rb'
- 'lib/reporting/reports/enterprise_fee_summary/parameters.rb'
# Offense count: 8
# Configuration parameters: Include.
# Include: app/models/**/*.rb
@@ -517,12 +487,6 @@ Rails/I18nLocaleTexts:
Exclude:
- 'app/controllers/admin/stripe_accounts_controller.rb'
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/IgnoredColumnsAssignment:
Exclude:
- 'app/models/spree/variant.rb'
# Offense count: 22
# Configuration parameters: IgnoreScopes, Include.
# Include: app/models/**/*.rb
@@ -623,22 +587,17 @@ Rails/PluckInWhere:
Exclude:
- 'app/models/spree/variant.rb'
# Offense count: 30
# Offense count: 22
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/RedundantPresenceValidationOnBelongsTo:
Exclude:
- 'app/models/enterprise.rb'
- 'app/models/enterprise_fee.rb'
- 'app/models/enterprise_group.rb'
- 'app/models/enterprise_relationship.rb'
- 'app/models/enterprise_role.rb'
- 'app/models/exchange.rb'
- 'app/models/inventory_item.rb'
- 'app/models/order_cycle.rb'
- 'app/models/spree/address.rb'
- 'app/models/spree/line_item.rb'
- 'app/models/spree/order.rb'
- 'app/models/spree/product.rb'
- 'app/models/spree/product_property.rb'
- 'app/models/spree/return_authorization.rb'
- 'app/models/spree/state.rb'
@@ -944,13 +903,6 @@ Style/GuardClause:
- 'spec/support/request/shop_workflow.rb'
- 'spec/system/support/precompile_assets.rb'
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: braces, no_braces
Style/HashAsLastArrayItem:
Exclude:
# Offense count: 12
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSplatArgument.
@@ -973,7 +925,7 @@ Style/HashLikeCase:
Exclude:
- 'app/models/enterprise.rb'
# Offense count: 1792
# Offense count: 1782
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
@@ -1222,7 +1174,6 @@ Style/HashSyntax:
- 'spec/models/concerns/order_shipment_spec.rb'
- 'spec/models/concerns/product_stock_spec.rb'
- 'spec/models/customer_spec.rb'
- 'spec/models/enterprise_caching_spec.rb'
- 'spec/models/enterprise_fee_spec.rb'
- 'spec/models/enterprise_relationship_spec.rb'
- 'spec/models/enterprise_spec.rb'
@@ -1236,7 +1187,6 @@ Style/HashSyntax:
- 'spec/models/spree/address_spec.rb'
- 'spec/models/spree/adjustment_spec.rb'
- 'spec/models/spree/calculator_spec.rb'
- 'spec/models/spree/classification_spec.rb'
- 'spec/models/spree/credit_card_spec.rb'
- 'spec/models/spree/gateway/stripe_sca_spec.rb'
- 'spec/models/spree/inventory_unit_spec.rb'
@@ -1520,6 +1470,17 @@ Style/RedundantRegexpArgument:
- 'app/models/spree/shipping_method.rb'
- 'lib/spree/i18n.rb'
# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Exclude:
- 'app/models/product_import/entry_validator.rb'
- 'app/models/spree/stock/availability_validator.rb'
- 'lib/reporting/reports/enterprise_fee_summary/summarizer.rb'
- 'lib/stripe/authorize_response_patcher.rb'
- 'lib/tasks/data.rake'
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantStringEscape:
@@ -1537,10 +1498,9 @@ Style/ReturnNilInPredicateMethodDefinition:
- 'app/serializers/api/admin/customer_serializer.rb'
- 'engines/order_management/app/services/order_management/subscriptions/validator.rb'
# Offense count: 205
# Offense count: 204
Style/Send:
Exclude:
- 'app/controllers/split_checkout_controller.rb'
- 'spec/controllers/admin/subscriptions_controller_spec.rb'
- 'spec/controllers/payment_gateways/paypal_controller_spec.rb'
- 'spec/controllers/spree/admin/base_controller_spec.rb'

View File

@@ -28,7 +28,7 @@ module Spree
if @user.save
if roles
@user.spree_roles = roles.reject(&:blank?).collect{ |r| Spree::Role.find(r) }
@user.spree_roles = roles.compact_blank.collect{ |r| Spree::Role.find(r) }
end
flash.now[:success] = Spree.t(:created_successfully)
@@ -45,7 +45,7 @@ module Spree
if @user.update(user_params)
if roles
@user.spree_roles = roles.reject(&:blank?).collect{ |r| Spree::Role.find(r) }
@user.spree_roles = roles.compact_blank.collect{ |r| Spree::Role.find(r) }
end
flash.now[:success] = update_message

View File

@@ -2,10 +2,10 @@
module AddressDisplay
def full_name_reverse
[lastname, firstname].reject(&:blank?).join(" ")
[lastname, firstname].compact_blank.join(" ")
end
def full_name_for_sorting
[last_name, first_name].reject(&:blank?).join(", ")
[last_name, first_name].compact_blank.join(", ")
end
end

View File

@@ -115,7 +115,7 @@ module Spree
def find_line_item_by_variant(variant, raise_error = false)
line_item = order.find_line_item_by_variant(variant)
if !line_item.present? && raise_error
if line_item.blank? && raise_error
raise ActiveRecord::RecordNotFound, "Line item not found for variant #{variant.sku}"
end

View File

@@ -90,7 +90,7 @@ module Spree
def country_ids=(ids)
zone_members.destroy_all
ids.reject(&:blank?).map do |id|
ids.compact_blank.map do |id|
member = ZoneMember.new
member.zoneable_type = 'Spree::Country'
member.zoneable_id = id
@@ -100,7 +100,7 @@ module Spree
def state_ids=(ids)
zone_members.destroy_all
ids.reject(&:blank?).map do |id|
ids.compact_blank.map do |id|
member = ZoneMember.new
member.zoneable_type = 'Spree::State'
member.zoneable_id = id

View File

@@ -12,7 +12,7 @@ class ContentSanitizer
}.freeze
def strip_content(content)
return unless content.present?
return if content.blank?
content = strip_tags(content.to_s.strip)
@@ -20,7 +20,7 @@ class ContentSanitizer
end
def sanitize_content(content)
return unless content.present?
return if content.blank?
content = sanitize(content.to_s, scrubber: ContentScrubber.new)

View File

@@ -113,7 +113,7 @@ class OrderCycleForm
def selected_distributor_payment_method_ids
@selected_distributor_payment_method_ids = (
attachable_distributor_payment_method_ids &
@selected_distributor_payment_method_ids.reject(&:blank?).map(&:to_i)
@selected_distributor_payment_method_ids.compact_blank.map(&:to_i)
)
if attachable_distributor_payment_method_ids.sort ==
@@ -131,7 +131,7 @@ class OrderCycleForm
def selected_distributor_shipping_method_ids
@selected_distributor_shipping_method_ids = (
attachable_distributor_shipping_method_ids &
@selected_distributor_shipping_method_ids.reject(&:blank?).map(&:to_i)
@selected_distributor_shipping_method_ids.compact_blank.map(&:to_i)
)
if attachable_distributor_shipping_method_ids.sort ==

View File

@@ -2,7 +2,7 @@
# Controller used to provide the API products for the DFC application
module DfcProvider
class BaseController < ActionController::Base
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session
rescue_from ActiveRecord::RecordNotFound, with: :not_found

View File

@@ -3,7 +3,7 @@
# Controller used to provide the API products for the DFC application
# CatalogItems are items that are being sold by the entreprise.
module DfcProvider
class CatalogItemsController < DfcProvider::BaseController
class CatalogItemsController < DfcProvider::ApplicationController
before_action :check_enterprise
def index

View File

@@ -2,7 +2,7 @@
# Controller used to provide the CatalogItem API for the DFC application
module DfcProvider
class EnterprisesController < DfcProvider::BaseController
class EnterprisesController < DfcProvider::ApplicationController
before_action :check_enterprise
def show

View File

@@ -2,7 +2,7 @@
# Controller used to provide the Persons API for the DFC application
module DfcProvider
class PersonsController < DfcProvider::BaseController
class PersonsController < DfcProvider::ApplicationController
before_action :check_user_accessibility
def show

View File

@@ -3,7 +3,7 @@
# Controller used to provide the SuppliedProducts API for the DFC application
# SuppliedProducts are products that are managed by an enterprise.
module DfcProvider
class SuppliedProductsController < DfcProvider::BaseController
class SuppliedProductsController < DfcProvider::ApplicationController
before_action :check_enterprise
rescue_from JSON::LD::JsonLdError::LoadingDocumentFailed, with: -> do
head :bad_request

View File

@@ -79,7 +79,7 @@ module OrderManagement
#
# @return [Array<Spree::ShippingMethod>]
def shipping_methods
return [] unless order.distributor.present?
return [] if order.distributor.blank?
order.distributor.shipping_methods.uniq.to_a
end

View File

@@ -22,7 +22,7 @@ module Reporting
def fields_to_hide
if report.display_header_row?
report.formatted_rules.map { |rule| rule[:fields_used_in_header] }.flatten.reject(&:blank?)
report.formatted_rules.map { |rule| rule[:fields_used_in_header] }.flatten.compact_blank
else
[]
end.concat(params_fields_to_hide)
@@ -32,7 +32,7 @@ module Reporting
fields_in_headers = if report.display_header_row?
report.formatted_rules.map { |rule|
rule[:fields_used_in_header]
}.flatten.reject(&:blank?)
}.flatten.compact_blank
else
[]
end

View File

@@ -55,7 +55,7 @@ module Reporting
rule[:fields_used_in_header] ||= rule[:header]
fields = rule[:header]
rule[:header] = proc do |_key, _items, rows|
fields.map { |field| rows.first[field] }.reject(&:blank?).join(' ')
fields.map { |field| rows.first[field] }.compact_blank.join(' ')
end
end
end

View File

@@ -46,12 +46,12 @@ module Reporting
#
# https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select
def cleanup_arrays
distributor_ids.reject!(&:blank?)
producer_ids.reject!(&:blank?)
order_cycle_ids.reject!(&:blank?)
enterprise_fee_ids.reject!(&:blank?)
shipping_method_ids.reject!(&:blank?)
payment_method_ids.reject!(&:blank?)
distributor_ids.compact_blank!
producer_ids.compact_blank!
order_cycle_ids.compact_blank!
enterprise_fee_ids.compact_blank!
shipping_method_ids.compact_blank!
payment_method_ids.compact_blank!
end
end
end

View File

@@ -22,7 +22,7 @@ module Stripe
return unless %w(requires_source_action requires_action).include?(response.params["status"])
next_action = response.params["next_source_action"] || response.params["next_action"]
return unless next_action.present?
return if next_action.blank?
next_action_type = next_action["type"]
return unless %w(authorize_with_url redirect_to_url).include?(next_action_type)