From e9f448fad9cb4c8183c3bea764d81995c389e911 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 28 Jul 2023 16:45:10 +0900 Subject: [PATCH 1/5] Safely autocorrect Lint/AmbiguousOperatorPrecedence Inspecting 1480 files ...................................................................................................................................................................................................................................W..........................W........................................................W................W..............W................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Offenses: app/models/calculator/flexi_rate.rb:38:7: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. count * preferred_additional_item.to_f + preferred_first_item.to_f ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/enterprise.rb:362:12: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. cat << "sells_" + sells ^^^^^^^^^^^^^^^^ app/models/enterprise.rb:496:21: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. phone_number && "https://wa.me/" + phone_number.tr('+ ', '') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/spree/ability.rb:27:33: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. order.user == user || order.token && token == order.token ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/spree/ability.rb:30:33: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. order.user == user || order.token && token == order.token ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/spree/line_item.rb:205:16: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. (price + fees / quantity).round(2) ^^^^^^^^^^^^^^^ app/models/spree/preferences/store.rb:28:11: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity. should_persist? && Spree::Preference.where(key: key).exists? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1480 files inspected, 7 offenses detected, 7 offenses corrected --- .rubocop_todo.yml | 14 ++------------ app/models/calculator/flexi_rate.rb | 2 +- app/models/enterprise.rb | 4 ++-- app/models/spree/ability.rb | 4 ++-- app/models/spree/line_item.rb | 2 +- app/models/spree/preferences/store.rb | 2 +- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bedff16039..4a5e6f12d6 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 @@ -1144,7 +1134,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/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..0f487a4913 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 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) From e7d53753e456ff380d02706e3997c6f48346931d Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 28 Jul 2023 16:38:13 +0900 Subject: [PATCH 2/5] Safely autocorrect Lint/RedundantCopDisableDirective Inspecting 1480 files ..............W......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Offenses: app/components/product_component.rb:23:51: W: [Corrected] Lint/RedundantCopDisableDirective: Unnecessary disabling of Metrics/MethodLength. # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength ^^^^^^^^^^^^^^^^^^^^ app/components/product_component.rb:50:50: W: [Corrected] Lint/RedundantCopEnableDirective: Unnecessary enabling of Metrics/MethodLength. # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength ^^^^^^^^^^^^^^^^^^^^ 1480 files inspected, 2 offenses detected, 2 offenses corrected --- .rubocop_todo.yml | 6 ------ app/components/product_component.rb | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4a5e6f12d6..fd8103bcdf 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -124,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: 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 From 2a76b1972f2ee08767d5051f1861dfc1c4d38d0f Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 28 Jul 2023 16:39:43 +0900 Subject: [PATCH 3/5] 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 --- .rubocop_todo.yml | 9 --------- app/models/spree/line_item.rb | 2 +- app/models/spree/stock/availability_validator.rb | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fd8103bcdf..80d87556df 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index 0f487a4913..1631832ca5 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -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/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: From ae8a5b7f939134ad0281f1fc73ac5bbe5097a82d Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 28 Jul 2023 16:41:12 +0900 Subject: [PATCH 4/5] Safely autocorrect Lint/UnusedMethodArgument Inspecting 1480 files ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................W............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Offenses: lib/reporting/queries/query_interface.rb:18:30: W: [Corrected] Lint/UnusedMethodArgument: Unused method argument - default. If it's necessary, use _ or _default as an argument name to indicate that it won't be used. If it's unnecessary, remove it. def sum_grouped(field, default = 0) ^^^^^^^ lib/reporting/queries/query_interface.rb:22:26: W: [Corrected] Lint/UnusedMethodArgument: Unused method argument - default. If it's necessary, use _ or _default as an argument name to indicate that it won't be used. If it's unnecessary, remove it. def sum_new(field, default = 0) ^^^^^^^ 1480 files inspected, 2 offenses detected, 2 offenses corrected --- .rubocop_todo.yml | 7 ------- lib/reporting/queries/query_interface.rb | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 80d87556df..cfa32511bc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -141,13 +141,6 @@ Lint/RedundantSafeNavigation: Exclude: - 'app/models/spree/payment.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: 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 From 60cd84d5658b2bc27604b12f6ef019a0dd4bd5bc Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 28 Jul 2023 16:42:44 +0900 Subject: [PATCH 5/5] Safely autocorrect Naming/BlockForwarding Inspecting 1480 files ...................................................................................................................................................................C.......C..........C...............................................................................................................................................................................................................C...........................................................................................................C.........C...............................................................................................................................................................................................................................................................C........................................CC...C............................................................................................................................................................................................................................................................................................................................C.....................................................................................................................................................................................................C..............C.........C..CC.......C.....................................................................................................C............... Offenses: app/helpers/application_helper.rb:41:32: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def ng_form_for(name, *args, &block) ^^^^^^ app/helpers/application_helper.rb:44:75: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. form_for(name, *(args << options.merge(builder: AngularFormBuilder)), &block) ^^^^^^ app/helpers/application_helper.rb:49:37: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def method_missing(method, *args, &block) ^^^^^^ app/helpers/link_helper.rb:4:57: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def link_to_service(baseurl, name, html_options = {}, &block) ^^^^^^ app/helpers/link_helper.rb:8:51: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. link_to ext_url(baseurl, name), html_options, &block ^^^^^^ app/helpers/spree/admin/base_helper.rb:6:56: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def field_container(model, method, options = {}, &block) ^^^^^^ app/helpers/spree/admin/base_helper.rb:13:29: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. capture(&block), ^^^^^^ app/reflexes/application_reflex.rb:29:19: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def with_locale(&block) ^^^^^^ app/reflexes/application_reflex.rb:30:43: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. I18n.with_locale(current_user.locale, &block) ^^^^^^ app/services/cache_service.rb:8:43: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def self.cache(cache_key, options = {}, &block) ^^^^^^ app/services/cache_service.rb:9:48: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. Rails.cache.fetch cache_key.to_s, options, &block ^^^^^^ app/services/cache_service.rb:14:58: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def self.cached_data_by_class(cache_key, cached_class, &block) ^^^^^^ app/services/cache_service.rb:16:23: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. &block ^^^^^^ app/services/cache_service.rb:25:34: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def self.home_stats(statistic, &block) ^^^^^^ app/services/cache_service.rb:28:47: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. race_condition_ttl: 10, &block) ^^^^^^ app/services/current_order_locker.rb:12:31: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def self.around(controller, &block) ^^^^^^ app/services/current_order_locker.rb:13:55: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. lock_order_and_variants(controller.current_order, &block) ^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:392:28: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def chain_to_scope(&block) ^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:393:41: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. @scope = @scope.instance_eval(&block) ^^^^^^ lib/spree/core/controller_helpers/respond_with.rb:7:34: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def respond_with(*resources, &block) ^^^^^^ lib/spree/core/controller_helpers/respond_with.rb:13:64: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. return unless (collector = retrieve_collector_from_mimes(&block)) ^^^^^^ lib/spree/core/delegate_belongs_to.rb:80:39: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def class_def(name, method = nil, &blk) ^^^^ lib/spree/core/delegate_belongs_to.rb:81:54: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. class_eval { method.nil? ? define_method(name, &blk) : define_method(name, method) } ^^^^ lib/spree/core/environment_extension.rb:22:31: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def create_method(name, &block) ^^^^^^ lib/spree/core/environment_extension.rb:23:51: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. self.class.__send__(:define_method, name, &block) ^^^^^^ spec/models/enterprise_caching_spec.rb:144:13: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def later(&block) ^^^^^^ spec/models/enterprise_caching_spec.rb:145:36: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. Timecop.travel(1.day.from_now, &block) ^^^^^^ spec/support/embedded_pages_helper.rb:5:26: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def on_embedded_page(&block) ^^^^^^ spec/support/embedded_pages_helper.rb:6:28: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. within_frame :frame, &block ^^^^^^ spec/support/preferences_helper.rb:11:31: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def reset_spree_preferences(&config_block) ^^^^^^^^^^^^^ spec/support/preferences_helper.rb:16:33: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. configure_spree_preferences(&config_block) if block_given? ^^^^^^^^^^^^^ spec/support/request/shop_workflow.rb:87:37: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def within_variant(variant = nil, &block) ^^^^^^ spec/support/request/shop_workflow.rb:90:22: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. within(selector, &block) ^^^^^^ spec/support/request/ui_component_helper.rb:4:23: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def browse_as_small(&block) ^^^^^^ spec/support/request/ui_component_helper.rb:5:39: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. browse_with_window_size(640, 480, &block) ^^^^^^ spec/support/request/ui_component_helper.rb:8:24: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def browse_as_medium(&block) ^^^^^^ spec/support/request/ui_component_helper.rb:9:40: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. browse_with_window_size(1024, 768, &block) ^^^^^^ spec/support/request/web_helper.rb:52:23: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def within_row(num, &block) ^^^^^^ spec/support/request/web_helper.rb:53:54: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. within("table.index tbody tr:nth-child(#{num})", &block) ^^^^^^ spec/swagger_helper.rb:77:19: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def param(args, &block) ^^^^^^ spec/swagger_helper.rb:78:45: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. public_send(:let, args) { instance_eval(&block) } ^^^^^^ spec/system/support/capybara_setup.rb:20:27: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding. def using_session(name, &block) ^^^^^^ 1480 files inspected, 42 offenses detected, 42 offenses corrected --- .rubocop_todo.yml | 25 ------------------- app/helpers/application_helper.rb | 6 ++--- app/helpers/link_helper.rb | 4 +-- app/helpers/spree/admin/base_helper.rb | 4 +-- app/reflexes/application_reflex.rb | 4 +-- app/services/cache_service.rb | 14 +++++------ app/services/current_order_locker.rb | 4 +-- .../reports/enterprise_fee_summary/scope.rb | 4 +-- .../core/controller_helpers/respond_with.rb | 4 +-- lib/spree/core/delegate_belongs_to.rb | 4 +-- lib/spree/core/environment_extension.rb | 4 +-- spec/models/enterprise_caching_spec.rb | 4 +-- spec/support/embedded_pages_helper.rb | 4 +-- spec/support/preferences_helper.rb | 4 +-- spec/support/request/shop_workflow.rb | 4 +-- spec/support/request/ui_component_helper.rb | 8 +++--- spec/support/request/web_helper.rb | 4 +-- spec/swagger_helper.rb | 4 +-- spec/system/support/capybara_setup.rb | 2 +- 19 files changed, 43 insertions(+), 68 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cfa32511bc..09ca46100a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -403,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|$)) 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/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/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