From 85fef7ac4b4f4253a4e5f8924c7930362ce23e4c Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 17 Nov 2023 08:59:27 +0900 Subject: [PATCH 1/3] Safely autocorrect Style/RedundantRegexpArgument Inspecting 1513 files ...........................................................................................................................................................................................................................................................................................................................................................C....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Offenses: app/models/spree/shipping_method.rb:69:25: C: [Corrected] Style/RedundantRegexpArgument: Use string ":tracking" as argument instead of regexp /:tracking/. tracking_url.gsub(/:tracking/, tracking) unless tracking.blank? || tracking_url.blank? ^^^^^^^^^^^ lib/spree/i18n.rb:36:17: C: [Corrected] Style/RedundantRegexpArgument: Use string "spree" as argument instead of regexp /spree/. path.gsub(/spree/, '') ^^^^^^^ 1513 files inspected, 2 offenses detected, 2 offenses corrected --- .rubocop_todo.yml | 7 ------- app/models/spree/shipping_method.rb | 2 +- lib/spree/i18n.rb | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 44eff7c575..7bb5fa3079 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -937,13 +937,6 @@ Style/RedundantInterpolation: - 'lib/tasks/karma.rake' - 'spec/base_spec_helper.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpArgument: - Exclude: - - 'app/models/spree/shipping_method.rb' - - 'lib/spree/i18n.rb' - # Offense count: 5 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowMultipleReturnValues. diff --git a/app/models/spree/shipping_method.rb b/app/models/spree/shipping_method.rb index 42ab253ef7..1f726a5d2a 100644 --- a/app/models/spree/shipping_method.rb +++ b/app/models/spree/shipping_method.rb @@ -66,7 +66,7 @@ module Spree end def build_tracking_url(tracking) - tracking_url.gsub(/:tracking/, tracking) unless tracking.blank? || tracking_url.blank? + tracking_url.gsub(":tracking", tracking) unless tracking.blank? || tracking_url.blank? end # Some shipping methods are only meant to be set via backend diff --git a/lib/spree/i18n.rb b/lib/spree/i18n.rb index 69242c3d07..38fbd40b00 100644 --- a/lib/spree/i18n.rb +++ b/lib/spree/i18n.rb @@ -33,7 +33,7 @@ module Spree return unless path - path.gsub(/spree/, '') + path.gsub("spree", '') end end end From edbf4c15a9378cd938bb5839c282006086c14297 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 17 Nov 2023 09:00:50 +0900 Subject: [PATCH 2/3] Safely autocorrect Style/RedundantReturn Inspecting 1513 files .........................................................................................................................................................................................................................................................................................................C......................................................C............................................................................................................................................................................................................................................................................................................................................................................................................................................C.........................................................C.......C......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Offenses: app/models/product_import/entry_validator.rb:200:7: C: [Corrected] Style/RedundantReturn: Redundant return detected. return true unless Float(value, exception: false).nil? ^^^^^^ app/models/spree/stock/availability_validator.rb:30:9: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause. return line_item.target_shipment if line_item.target_shipment ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/spree/stock/availability_validator.rb:31:9: C: [Corrected] Style/RedundantReturn: Redundant return detected. return line_item.order.shipments.first if line_item.order&.shipments&.any? ^^^^^^ lib/reporting/reports/enterprise_fee_summary/summarizer.rb:41:11: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause. return DataRepresentations::IncomingExchangeLineItemFee if for_incoming_exchange? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/summarizer.rb:42:11: C: [Corrected] Style/RedundantReturn: Redundant return detected. return DataRepresentations::OutgoingExchangeLineItemFee if for_outgoing_exchange? ^^^^^^ lib/stripe/authorize_response_patcher.rb:31:7: C: [Corrected] Style/RedundantReturn: Redundant return detected. return url if url.match(%r{https?://\S+}) && url.include?("stripe.com") ^^^^^^ lib/tasks/data.rake:99:7: C: [Corrected] Style/RedundantReturn: Redundant return detected. return true if Integer(value) ^^^^^^ 1513 files inspected, 7 offenses detected, 7 offenses corrected --- .rubocop_todo.yml | 11 ----------- app/models/product_import/entry_validator.rb | 2 +- app/models/spree/stock/availability_validator.rb | 3 ++- .../reports/enterprise_fee_summary/summarizer.rb | 3 ++- lib/stripe/authorize_response_patcher.rb | 2 +- lib/tasks/data.rake | 2 +- 6 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7bb5fa3079..b7fa6eacda 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -937,17 +937,6 @@ Style/RedundantInterpolation: - 'lib/tasks/karma.rake' - 'spec/base_spec_helper.rb' -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'app/models/product_import/entry_validator.rb' - - 'app/models/spree/stock/availability_validator.rb' - - 'lib/reporting/reports/enterprise_fee_summary/summarizer.rb' - - 'lib/stripe/authorize_response_patcher.rb' - - 'lib/tasks/data.rake' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Style/RedundantSelf: diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 1e4e6be649..9eaed6034a 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -197,7 +197,7 @@ module ProductImport end def is_numeric(value) - return true unless Float(value, exception: false).nil? + true unless Float(value, exception: false).nil? end def price_validation(entry) diff --git a/app/models/spree/stock/availability_validator.rb b/app/models/spree/stock/availability_validator.rb index 513b9fbc61..cdbcebe47b 100644 --- a/app/models/spree/stock/availability_validator.rb +++ b/app/models/spree/stock/availability_validator.rb @@ -28,7 +28,8 @@ 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? + + line_item.order.shipments.first if line_item.order&.shipments&.any? end # Overrides Spree v2.0.4 validate method version to: diff --git a/lib/reporting/reports/enterprise_fee_summary/summarizer.rb b/lib/reporting/reports/enterprise_fee_summary/summarizer.rb index d7651f69d4..98ec391fa8 100644 --- a/lib/reporting/reports/enterprise_fee_summary/summarizer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/summarizer.rb @@ -39,7 +39,8 @@ module Reporting return DataRepresentations::ExchangeOrderFee if for_order_adjustment_source? return unless for_line_item_adjustment_source? return DataRepresentations::IncomingExchangeLineItemFee if for_incoming_exchange? - return DataRepresentations::OutgoingExchangeLineItemFee if for_outgoing_exchange? + + DataRepresentations::OutgoingExchangeLineItemFee if for_outgoing_exchange? end def for_payment_method? diff --git a/lib/stripe/authorize_response_patcher.rb b/lib/stripe/authorize_response_patcher.rb index 3ddac6ee51..4128bf6577 100644 --- a/lib/stripe/authorize_response_patcher.rb +++ b/lib/stripe/authorize_response_patcher.rb @@ -28,7 +28,7 @@ module Stripe return unless %w(authorize_with_url redirect_to_url).include?(next_action_type) url = next_action[next_action_type]["url"] - return url if url.match(%r{https?://\S+}) && url.include?("stripe.com") + url if url.match(%r{https?://\S+}) && url.include?("stripe.com") end # This field is used because the Spree code recognizes and stores it diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 1162a94896..da55b3580e 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -96,7 +96,7 @@ namespace :ofn do end def is_integer?(value) - return true if Integer(value) + true if Integer(value) rescue StandardError false end From c3c4486d0c4426f39a7d616ef1cf6aa6ce0e14d0 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 17 Nov 2023 09:03:32 +0900 Subject: [PATCH 3/3] Safely autocorrect Style/RedundantStringEscape Inspecting 1513 files ..........................................................................................................................................................................................................................................................................................................................C...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C......................................................................................................................................................................................................................................................................................................................................................................................................................................................................C........................................................................................................... Offenses: app/models/spree/calculator.rb:31:48: C: [Corrected] Style/RedundantStringEscape: Redundant escape of / inside string literal. self.class.name.titleize.gsub("Calculator\/", "") ^^ spec/controllers/spree/admin/shipping_methods_controller_spec.rb:40:78: C: [Corrected] Style/RedundantStringEscape: Redundant escape of ' inside string literal. params[:shipping_method][:calculator_attributes][shipping_amount] = "\'20.0'" ^^ spec/system/admin/enterprise_fees_spec.rb:82:78: C: [Corrected] Style/RedundantStringEscape: Redundant escape of ' inside string literal. fill_in("#{prefix}_calculator_attributes_preferred_flat_percent", with: "\'20.0'") ^^ spec/system/admin/enterprise_fees_spec.rb:140:42: C: [Corrected] Style/RedundantStringEscape: Redundant escape of ' inside string literal. 'preferred_flat_percent', with: "\'20.0'" ^^ 1513 files inspected, 4 offenses detected, 4 offenses corrected --- .rubocop_todo.yml | 14 -------------- app/models/spree/calculator.rb | 2 +- app/models/spree/order.rb | 2 +- .../admin/shipping_methods_controller_spec.rb | 2 +- spec/system/admin/enterprise_fees_spec.rb | 4 ++-- 5 files changed, 5 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b7fa6eacda..aa12b8a9a5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -937,20 +937,6 @@ Style/RedundantInterpolation: - 'lib/tasks/karma.rake' - 'spec/base_spec_helper.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantSelf: - Exclude: - - 'app/models/spree/order.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantStringEscape: - Exclude: - - 'app/models/spree/calculator.rb' - - 'spec/controllers/spree/admin/shipping_methods_controller_spec.rb' - - 'spec/system/admin/enterprise_fees_spec.rb' - # Offense count: 19 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedMethods, AllowedPatterns. diff --git a/app/models/spree/calculator.rb b/app/models/spree/calculator.rb index 1b561d2549..9ff0e53651 100644 --- a/app/models/spree/calculator.rb +++ b/app/models/spree/calculator.rb @@ -28,7 +28,7 @@ module Spree end def to_s - self.class.name.titleize.gsub("Calculator\/", "") + self.class.name.titleize.gsub("Calculator/", "") end def description diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 51851d032a..3dced4e802 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -205,7 +205,7 @@ module Spree end def display_payment_total - Spree::Money.new(self.payment_total, currency:) + Spree::Money.new(payment_total, currency:) end def to_param diff --git a/spec/controllers/spree/admin/shipping_methods_controller_spec.rb b/spec/controllers/spree/admin/shipping_methods_controller_spec.rb index dcc4f1c5c0..e93103e2d6 100644 --- a/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/shipping_methods_controller_spec.rb @@ -37,7 +37,7 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do ].each do |shipping_amount| it "diplay error message on update if #{shipping_amount} input is invalid" do shipping_method.calculator = create(:calculator_flat_rate, calculable: shipping_method) - params[:shipping_method][:calculator_attributes][shipping_amount] = "\'20.0'" + params[:shipping_method][:calculator_attributes][shipping_amount] = "'20.0'" spree_post :update, params diff --git a/spec/system/admin/enterprise_fees_spec.rb b/spec/system/admin/enterprise_fees_spec.rb index 4cbaeea641..a227c0e49e 100644 --- a/spec/system/admin/enterprise_fees_spec.rb +++ b/spec/system/admin/enterprise_fees_spec.rb @@ -79,7 +79,7 @@ describe ' expect(page).to have_selector "input[value='Hello!']" # When I fill in the calculator fields and click update - fill_in("#{prefix}_calculator_attributes_preferred_flat_percent", with: "\'20.0'") + fill_in("#{prefix}_calculator_attributes_preferred_flat_percent", with: "'20.0'") click_button 'Update' # Then I should see the flash error message @@ -137,7 +137,7 @@ describe ' # When I fill in the calculator fields and click update fill_in( "#{prefix}_calculator_attributes_" \ - 'preferred_flat_percent', with: "\'20.0'" + 'preferred_flat_percent', with: "'20.0'" ) click_button 'Update'