Skip to content

Commit

Permalink
Merge pull request #11300 from macanudo527/fix_rubocop_layout_3
Browse files Browse the repository at this point in the history
Fix rubocop layout 4
  • Loading branch information
mkllnk authored Jul 31, 2023
2 parents 0bcde2d + 60cd84d commit c8ad6d7
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 115 deletions.
61 changes: 2 additions & 59 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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|$))
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions app/components/product_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def collection_key
@product.id
end

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity
def column_value(column)
case column
when 'name'
Expand All @@ -47,7 +47,7 @@ def column_value(column)
format_date(@product.import_date)
end
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity

private

Expand Down
6 changes: 3 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def language_meta_tags
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
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/link_helper.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/spree/admin/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/calculator/flexi_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def compute(object)
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
4 changes: 2 additions & 2 deletions app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def is_hub
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
Expand Down Expand Up @@ -493,7 +493,7 @@ def strip_url(url)
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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/spree/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def initialize(user)
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
Expand Down
4 changes: 2 additions & 2 deletions app/models/spree/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def price_with_adjustments

fees = adjustments.enterprise_fee.sum(:amount)

(price + fees / quantity).round(2)
(price + (fees / quantity)).round(2)
end

def single_display_amount_with_adjustments
Expand Down Expand Up @@ -280,7 +280,7 @@ def calculate_final_weight_volume
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/preferences/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def set(key, value, type)

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)
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/stock/availability_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def quantity_in_shipment(line_item)

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:
Expand Down
4 changes: 2 additions & 2 deletions app/reflexes/application_reflex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def current_ability
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
Expand Down
14 changes: 7 additions & 7 deletions app/services/cache_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,10 +22,10 @@ def self.latest_timestamp_by_class(cached_class)
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
Expand Down
4 changes: 2 additions & 2 deletions app/services/current_order_locker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/reporting/queries/query_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def sum_values(field, default = 0)
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

Expand Down
4 changes: 2 additions & 2 deletions lib/reporting/reports/enterprise_fee_summary/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ def select_attributes
end
end

def chain_to_scope(&block)
@scope = @scope.instance_eval(&block)
def chain_to_scope(&)
@scope = @scope.instance_eval(&)
self
end

Expand Down
4 changes: 2 additions & 2 deletions lib/spree/core/controller_helpers/respond_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

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!

Expand Down
4 changes: 2 additions & 2 deletions lib/spree/core/delegate_belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def initialize_association(type, association, opts = {})

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

Expand Down
4 changes: 2 additions & 2 deletions lib/spree/core/environment_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def add_class(name)

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
Expand Down
4 changes: 2 additions & 2 deletions spec/models/enterprise_caching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
end
end

def later(&block)
Timecop.travel(1.day.from_now, &block)
def later(&)
Timecop.travel(1.day.from_now, &)
end
end
4 changes: 2 additions & 2 deletions spec/support/embedded_pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit c8ad6d7

Please sign in to comment.