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
This commit is contained in:
Neal Chambers
2023-07-28 16:42:44 +09:00
parent ae8a5b7f93
commit 60cd84d565
19 changed files with 43 additions and 68 deletions

View File

@@ -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|$))

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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!

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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