diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bedff16039..09ca46100a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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.54.2. +# using RuboCop version 1.55.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 @@ -34,16 +34,6 @@ Layout/LineLength: - 'spec/system/consumer/shopping/cart_spec.rb' - 'spec/system/consumer/shopping/products_spec.rb' -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -Lint/AmbiguousOperatorPrecedence: - Exclude: - - 'app/models/calculator/flexi_rate.rb' - - 'app/models/enterprise.rb' - - 'app/models/spree/ability.rb' - - 'app/models/spree/line_item.rb' - - 'app/models/spree/preferences/store.rb' - # Offense count: 17 # Configuration parameters: AllowedMethods. # AllowedMethods: enums @@ -134,12 +124,6 @@ Lint/NonAtomicFileOperation: Exclude: - 'app/services/bulk_invoice_service.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Lint/RedundantCopDisableDirective: - Exclude: - - 'app/components/product_component.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). Lint/RedundantDirGlobSort: @@ -157,22 +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. -Lint/UnusedMethodArgument: - Exclude: - - 'lib/reporting/queries/query_interface.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Lint/UselessMethodDefinition: @@ -435,31 +403,6 @@ Naming/AccessorMethodName: - 'spec/support/request/shop_workflow.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 42 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, BlockForwardingName. -# SupportedStyles: anonymous, explicit -Naming/BlockForwarding: - Exclude: - - 'app/helpers/application_helper.rb' - - 'app/helpers/link_helper.rb' - - 'app/helpers/spree/admin/base_helper.rb' - - 'app/reflexes/application_reflex.rb' - - 'app/services/cache_service.rb' - - 'app/services/current_order_locker.rb' - - 'lib/reporting/reports/enterprise_fee_summary/scope.rb' - - 'lib/spree/core/controller_helpers/respond_with.rb' - - 'lib/spree/core/delegate_belongs_to.rb' - - 'lib/spree/core/environment_extension.rb' - - 'spec/models/enterprise_caching_spec.rb' - - 'spec/support/embedded_pages_helper.rb' - - 'spec/support/preferences_helper.rb' - - 'spec/support/request/shop_workflow.rb' - - 'spec/support/request/ui_component_helper.rb' - - 'spec/support/request/web_helper.rb' - - 'spec/swagger_helper.rb' - - 'spec/system/support/capybara_setup.rb' - # Offense count: 1 # Configuration parameters: ForbiddenDelimiters. # ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) @@ -1144,7 +1087,7 @@ Style/HashAsLastArrayItem: - 'app/components/products_table_component.rb' # Offense count: 12 -# This cop supports safe autocorrection (--autocorrect). +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSplatArgument. Style/HashConversion: Exclude: diff --git a/app/components/product_component.rb b/app/components/product_component.rb index c3f859116c..4a22f3b387 100644 --- a/app/components/product_component.rb +++ b/app/components/product_component.rb @@ -20,7 +20,7 @@ class ProductComponent < ViewComponentReflex::Component @product.id end - # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength + # rubocop:disable Metrics/CyclomaticComplexity def column_value(column) case column when 'name' @@ -47,7 +47,7 @@ class ProductComponent < ViewComponentReflex::Component format_date(@product.import_date) end end - # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength + # rubocop:enable Metrics/CyclomaticComplexity private diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ea8c4beeab..817d7badf5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -38,15 +38,15 @@ module ApplicationHelper end.join("\n").html_safe end - def ng_form_for(name, *args, &block) + def ng_form_for(name, *args, &) options = args.extract_options! - form_for(name, *(args << options.merge(builder: AngularFormBuilder)), &block) + form_for(name, *(args << options.merge(builder: AngularFormBuilder)), &) end # Pass URL helper calls on to spree where applicable so that we don't need to use # spree.foo_path in any view rendered from non-spree-namespaced controllers. - def method_missing(method, *args, &block) + def method_missing(method, *args, &) if method.to_s.end_with?('_path', '_url') && spree.respond_to?(method) spree.public_send(method, *args) else diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 016fa8fda6..98a0f43e5c 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true module LinkHelper - def link_to_service(baseurl, name, html_options = {}, &block) + def link_to_service(baseurl, name, html_options = {}, &) return if name.blank? html_options = html_options.merge target: '_blank' - link_to ext_url(baseurl, name), html_options, &block + link_to(ext_url(baseurl, name), html_options, &) end def ext_url(prefix, url) diff --git a/app/helpers/spree/admin/base_helper.rb b/app/helpers/spree/admin/base_helper.rb index d527b04d1d..31bf441649 100644 --- a/app/helpers/spree/admin/base_helper.rb +++ b/app/helpers/spree/admin/base_helper.rb @@ -3,14 +3,14 @@ module Spree module Admin module BaseHelper - def field_container(model, method, options = {}, &block) + def field_container(model, method, options = {}, &) css_classes = options[:class].to_a css_classes << 'field' if error_message_on(model, method).present? css_classes << 'withError' end content_tag(:div, - capture(&block), + capture(&), class: css_classes.join(' '), id: "#{model}_#{method}_field") end diff --git a/app/models/calculator/flexi_rate.rb b/app/models/calculator/flexi_rate.rb index 1959aec67e..c9ba7ef7f0 100644 --- a/app/models/calculator/flexi_rate.rb +++ b/app/models/calculator/flexi_rate.rb @@ -35,7 +35,7 @@ module Calculator private def compute_for(count) - count * preferred_additional_item.to_f + preferred_first_item.to_f + (count * preferred_additional_item.to_f) + preferred_first_item.to_f end end end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 494d40fead..99ce5c85c7 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -359,7 +359,7 @@ class Enterprise < ApplicationRecord def category # Make this crazy logic human readable so we can argue about it sanely. cat = is_primary_producer ? "producer_" : "non_producer_" - cat << "sells_" + sells + cat << ("sells_" + sells) # Map backend cases to front end cases. case cat @@ -493,7 +493,7 @@ class Enterprise < ApplicationRecord end def correct_whatsapp_url(phone_number) - phone_number && "https://wa.me/" + phone_number.tr('+ ', '') + phone_number && ("https://wa.me/" + phone_number.tr('+ ', '')) end def correct_instagram_url(url) diff --git a/app/models/spree/ability.rb b/app/models/spree/ability.rb index 1da1374b9d..fe0db0be6e 100644 --- a/app/models/spree/ability.rb +++ b/app/models/spree/ability.rb @@ -24,10 +24,10 @@ module Spree can [:index, :read], Country can :create, Order can :read, Order do |order, token| - order.user == user || order.token && token == order.token + order.user == user || (order.token && token == order.token) end can :update, Order do |order, token| - order.user == user || order.token && token == order.token + order.user == user || (order.token && token == order.token) end can [:index, :read], Product can [:index, :read], ProductProperty diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index ef0ea3a86b..1631832ca5 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -202,7 +202,7 @@ module Spree fees = adjustments.enterprise_fee.sum(:amount) - (price + fees / quantity).round(2) + (price + (fees / quantity)).round(2) end def single_display_amount_with_adjustments @@ -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 diff --git a/app/models/spree/preferences/store.rb b/app/models/spree/preferences/store.rb index 5eff5b2864..8ede8e3901 100644 --- a/app/models/spree/preferences/store.rb +++ b/app/models/spree/preferences/store.rb @@ -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: key).exists?) end def get(key, fallback = nil) diff --git a/app/models/spree/stock/availability_validator.rb b/app/models/spree/stock/availability_validator.rb index fc94efd1c6..513b9fbc61 100644 --- a/app/models/spree/stock/availability_validator.rb +++ b/app/models/spree/stock/availability_validator.rb @@ -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: diff --git a/app/reflexes/application_reflex.rb b/app/reflexes/application_reflex.rb index 4ed251f8bb..941a8c4f0c 100644 --- a/app/reflexes/application_reflex.rb +++ b/app/reflexes/application_reflex.rb @@ -26,8 +26,8 @@ class ApplicationReflex < StimulusReflex::Reflex Spree::Ability.new(current_user) end - def with_locale(&block) - I18n.with_locale(current_user.locale, &block) + def with_locale(&) + I18n.with_locale(current_user.locale, &) end def morph_admin_flashes diff --git a/app/services/cache_service.rb b/app/services/cache_service.rb index 4e6c92fa30..dd5dde54ca 100644 --- a/app/services/cache_service.rb +++ b/app/services/cache_service.rb @@ -5,15 +5,15 @@ class CacheService FILTERS_EXPIRY = 30.seconds.freeze SHOPS_EXPIRY = 15.seconds.freeze - def self.cache(cache_key, options = {}, &block) - Rails.cache.fetch cache_key.to_s, options, &block + def self.cache(cache_key, options = {}, &) + Rails.cache.fetch(cache_key.to_s, options, &) end # Yields a cached query, expired by the most recently updated record for a given class. # E.g: if *any* Spree::Taxon record is updated, all keys based on Spree::Taxon will auto-expire. - def self.cached_data_by_class(cache_key, cached_class, &block) - Rails.cache.fetch "#{cache_key}-#{cached_class}-#{latest_timestamp_by_class(cached_class)}", - &block + def self.cached_data_by_class(cache_key, cached_class, &) + Rails.cache.fetch("#{cache_key}-#{cached_class}-#{latest_timestamp_by_class(cached_class)}", + &) end # Gets the :updated_at value of the most recently updated record for a given class, and returns @@ -22,10 +22,10 @@ class CacheService cached_class.maximum(:updated_at).to_f end - def self.home_stats(statistic, &block) + def self.home_stats(statistic, &) Rails.cache.fetch("home_stats_count_#{statistic}", expires_in: HOME_STATS_EXPIRY, - race_condition_ttl: 10, &block) + race_condition_ttl: 10, &) end module FragmentCaching diff --git a/app/services/current_order_locker.rb b/app/services/current_order_locker.rb index fe47eebddb..1584701d1a 100644 --- a/app/services/current_order_locker.rb +++ b/app/services/current_order_locker.rb @@ -9,8 +9,8 @@ class CurrentOrderLocker # # https://guides.rubyonrails.org/action_controller_overview.html#filters # - def self.around(controller, &block) - lock_order_and_variants(controller.current_order, &block) + def self.around(controller, &) + lock_order_and_variants(controller.current_order, &) end # Locking will not prevent all access to these rows. Other processes are diff --git a/lib/reporting/queries/query_interface.rb b/lib/reporting/queries/query_interface.rb index b2b26b5f27..54d818cc9c 100644 --- a/lib/reporting/queries/query_interface.rb +++ b/lib/reporting/queries/query_interface.rb @@ -15,11 +15,11 @@ module Reporting NamedFunction.new("SUM", [coalesce(field, default)]) end - def sum_grouped(field, default = 0) + def sum_grouped(field, _default = 0) Case.new(sql_grouping(grouping_fields)).when(0).then(field.maximum).else(field.sum) end - def sum_new(field, default = 0) + def sum_new(field, _default = 0) Case.new(sql_grouping(grouping_fields)).when(0).then(field.maximum).else(sum_values(field)) end diff --git a/lib/reporting/reports/enterprise_fee_summary/scope.rb b/lib/reporting/reports/enterprise_fee_summary/scope.rb index 651ecbb035..0691dff04f 100644 --- a/lib/reporting/reports/enterprise_fee_summary/scope.rb +++ b/lib/reporting/reports/enterprise_fee_summary/scope.rb @@ -389,8 +389,8 @@ module Reporting end end - def chain_to_scope(&block) - @scope = @scope.instance_eval(&block) + def chain_to_scope(&) + @scope = @scope.instance_eval(&) self end diff --git a/lib/spree/core/controller_helpers/respond_with.rb b/lib/spree/core/controller_helpers/respond_with.rb index c35a071f25..3035cdea91 100644 --- a/lib/spree/core/controller_helpers/respond_with.rb +++ b/lib/spree/core/controller_helpers/respond_with.rb @@ -4,13 +4,13 @@ require 'spree/responder' module ActionController class Base - def respond_with(*resources, &block) + def respond_with(*resources, &) if self.class.mimes_for_respond_to.empty? raise "In order to use respond_with, first you need to declare the formats your " \ "controller responds to in the class level" end - return unless (collector = retrieve_collector_from_mimes(&block)) + return unless (collector = retrieve_collector_from_mimes(&)) options = resources.size == 1 ? {} : resources.extract_options! diff --git a/lib/spree/core/delegate_belongs_to.rb b/lib/spree/core/delegate_belongs_to.rb index 811a8d796d..fafe97392a 100644 --- a/lib/spree/core/delegate_belongs_to.rb +++ b/lib/spree/core/delegate_belongs_to.rb @@ -77,8 +77,8 @@ module DelegateBelongsTo private - def class_def(name, method = nil, &blk) - class_eval { method.nil? ? define_method(name, &blk) : define_method(name, method) } + def class_def(name, method = nil, &) + class_eval { method.nil? ? define_method(name, &) : define_method(name, method) } end end diff --git a/lib/spree/core/environment_extension.rb b/lib/spree/core/environment_extension.rb index 7b05908752..674ed9dbf2 100644 --- a/lib/spree/core/environment_extension.rb +++ b/lib/spree/core/environment_extension.rb @@ -19,8 +19,8 @@ module Spree private - def create_method(name, &block) - self.class.__send__(:define_method, name, &block) + def create_method(name, &) + self.class.__send__(:define_method, name, &) end end end diff --git a/spec/models/enterprise_caching_spec.rb b/spec/models/enterprise_caching_spec.rb index eed464940d..6747446ef8 100644 --- a/spec/models/enterprise_caching_spec.rb +++ b/spec/models/enterprise_caching_spec.rb @@ -141,7 +141,7 @@ describe Enterprise do end end - def later(&block) - Timecop.travel(1.day.from_now, &block) + def later(&) + Timecop.travel(1.day.from_now, &) end end diff --git a/spec/support/embedded_pages_helper.rb b/spec/support/embedded_pages_helper.rb index 30a0a04749..bfacb47c09 100644 --- a/spec/support/embedded_pages_helper.rb +++ b/spec/support/embedded_pages_helper.rb @@ -2,8 +2,8 @@ module OpenFoodNetwork module EmbeddedPagesHelper - def on_embedded_page(&block) - within_frame :frame, &block + def on_embedded_page(&) + within_frame(:frame, &) end end end diff --git a/spec/support/preferences_helper.rb b/spec/support/preferences_helper.rb index b69f5e8215..4a69d5c847 100644 --- a/spec/support/preferences_helper.rb +++ b/spec/support/preferences_helper.rb @@ -8,12 +8,12 @@ module PreferencesHelper # config.site_name = "my fancy pants store" # end # - def reset_spree_preferences(&config_block) + def reset_spree_preferences(&) Spree::Preferences::Store.instance.persistence = false Spree::Preferences::Store.instance.clear_cache config = Rails.application.config.spree.preferences - configure_spree_preferences(&config_block) if block_given? + configure_spree_preferences(&) if block_given? end def configure_spree_preferences diff --git a/spec/support/request/shop_workflow.rb b/spec/support/request/shop_workflow.rb index c7f21a9447..386fe4977f 100644 --- a/spec/support/request/shop_workflow.rb +++ b/spec/support/request/shop_workflow.rb @@ -84,10 +84,10 @@ module ShopWorkflow wait_for_cart end - def within_variant(variant = nil, &block) + def within_variant(variant = nil, &) selector = variant ? "#variant-#{variant.id}" : ".variants" expect(page).to have_selector selector - within(selector, &block) + within(selector, &) end def open_bulk_quantity_modal(variant) diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index ee7aedfbfe..30d6d02d4f 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true module UIComponentHelper - def browse_as_small(&block) - browse_with_window_size(640, 480, &block) + def browse_as_small(&) + browse_with_window_size(640, 480, &) end - def browse_as_medium(&block) - browse_with_window_size(1024, 768, &block) + def browse_as_medium(&) + browse_with_window_size(1024, 768, &) end def browse_as_default(&block) diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index b592bd728b..b20b31bf45 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -49,8 +49,8 @@ module WebHelper end end - def within_row(num, &block) - within("table.index tbody tr:nth-child(#{num})", &block) + def within_row(num, &) + within("table.index tbody tr:nth-child(#{num})", &) end def select2_select(value, options) diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index 40baea9c32..3b71cf2fe2 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -74,8 +74,8 @@ RSpec.configure do |config| end module RswagExtension - def param(args, &block) - public_send(:let, args) { instance_eval(&block) } + def param(args, &) + public_send(:let, args) { instance_eval(&) } end end Rswag::Specs::ExampleGroupHelpers.prepend RswagExtension diff --git a/spec/system/support/capybara_setup.rb b/spec/system/support/capybara_setup.rb index 6abf0653d0..e253f192fe 100644 --- a/spec/system/support/capybara_setup.rb +++ b/spec/system/support/capybara_setup.rb @@ -17,7 +17,7 @@ Capybara.save_path = ENV.fetch("CAPYBARA_ARTIFACTS", "./tmp/capybara") Capybara.singleton_class.prepend(Module.new do attr_accessor :last_used_session - def using_session(name, &block) + def using_session(name, &) self.last_used_session = name super ensure