From 0ec03da30e416881dc38821b705017856782f34b Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Thu, 9 Nov 2023 09:24:23 +0900 Subject: [PATCH 1/6] Regenerate Rubocop's TODO file --- .rubocop_todo.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8ab09cda6d..d5b4fe7cc7 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.57.1. +# using RuboCop version 1.57.2. # 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 @@ -180,7 +180,7 @@ Metrics/AbcSize: - 'lib/tasks/enterprises.rake' - 'spec/services/order_checkout_restart_spec.rb' -# Offense count: 45 +# Offense count: 44 # Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns. # AllowedMethods: refine Metrics/BlockLength: @@ -605,7 +605,7 @@ Rails/RedundantActiveRecordAllMethod: - 'app/models/spree/variant.rb' - 'spec/system/admin/product_import_spec.rb' -# Offense count: 22 +# Offense count: 20 # This cop supports unsafe autocorrection (--autocorrect-all). Rails/RedundantPresenceValidationOnBelongsTo: Exclude: @@ -622,7 +622,6 @@ Rails/RedundantPresenceValidationOnBelongsTo: - 'app/models/spree/stock_item.rb' - 'app/models/spree/stock_movement.rb' - 'app/models/spree/tax_rate.rb' - - 'app/models/spree/variant.rb' - 'app/models/subscription_line_item.rb' - 'app/models/tag_rule.rb' - 'app/models/variant_override.rb' From 69e7419a4547f92b863486fdf9d4553e9be8b945 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Thu, 9 Nov 2023 09:34:59 +0900 Subject: [PATCH 2/6] Safely autocorrect Style/NegatedIfElseCondition Inspecting 1509 files ....................................................................................................................................................................................................................C........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C....................................................................................................................................................... Offenses: app/mailers/spree/shipment_mailer.rb:15:25: C: [Corrected] Style/NegatedIfElseCondition: Invert the negated condition and swap the ternary branches. default_subject = !@delivery ? t('.picked_up_subject') : default_i18n_subject ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/support/matchers/table_matchers.rb:34:5: C: [Corrected] Style/NegatedIfElseCondition: Invert the negated condition and swap the if-else branches. if rows.count != expected_table.count ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1509 files inspected, 2 offenses detected, 2 offenses corrected --- .rubocop_todo.yml | 39 ------------------------- app/mailers/spree/shipment_mailer.rb | 2 +- app/models/spree/order.rb | 3 +- app/reflexes/white_label_reflex.rb | 2 +- spec/support/matchers/table_matchers.rb | 8 ++--- 5 files changed, 8 insertions(+), 46 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d5b4fe7cc7..766c7a3275 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,38 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/ArgumentAlignment: - Exclude: - - 'app/reflexes/white_label_reflex.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'app/models/spree/order.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'app/reflexes/white_label_reflex.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Width, AllowedPatterns. -Layout/IndentationWidth: - Exclude: - - 'app/models/spree/order.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. @@ -895,13 +863,6 @@ Style/MissingRespondToMissing: - 'app/models/spree/gateway.rb' - 'app/models/spree/preferences/configuration.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/NegatedIfElseCondition: - Exclude: - - 'app/mailers/spree/shipment_mailer.rb' - - 'spec/support/matchers/table_matchers.rb' - # Offense count: 22 # This cop supports safe autocorrection (--autocorrect). Style/NestedModifier: diff --git a/app/mailers/spree/shipment_mailer.rb b/app/mailers/spree/shipment_mailer.rb index cbe9bc62e6..0be7b55cca 100644 --- a/app/mailers/spree/shipment_mailer.rb +++ b/app/mailers/spree/shipment_mailer.rb @@ -12,7 +12,7 @@ module Spree private def base_subject - default_subject = !@delivery ? t('.picked_up_subject') : default_i18n_subject + default_subject = @delivery ? default_i18n_subject : t('.picked_up_subject') "#{@shipment.order.distributor.name} #{default_subject} ##{@shipment.order.number}" end end diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index cd1d9c81f7..51851d032a 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -205,8 +205,9 @@ module Spree end def display_payment_total - Spree::Money.new(self.payment_total, currency:) + Spree::Money.new(self.payment_total, currency:) end + def to_param number.to_s.parameterize.upcase end diff --git a/app/reflexes/white_label_reflex.rb b/app/reflexes/white_label_reflex.rb index ac7fa4983b..32aa6618bc 100644 --- a/app/reflexes/white_label_reflex.rb +++ b/app/reflexes/white_label_reflex.rb @@ -12,7 +12,7 @@ class WhiteLabelReflex < ApplicationReflex f = ActionView::Helpers::FormBuilder.new(:enterprise, @enterprise, view_context, {}) html = render(partial: "admin/enterprises/form/white_label", - locals: { f:, enterprise: @enterprise }) + locals: { f:, enterprise: @enterprise }) morph "#white_label_panel", html flash[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success") diff --git a/spec/support/matchers/table_matchers.rb b/spec/support/matchers/table_matchers.rb index 09b9f694ee..aaee09ed83 100644 --- a/spec/support/matchers/table_matchers.rb +++ b/spec/support/matchers/table_matchers.rb @@ -31,10 +31,7 @@ RSpec::Matchers.define :match_table do |expected_table| all("tr"). map { |r| r.all("th,td").map { |c| c.text.strip } } - if rows.count != expected_table.count - @failure_message = "found table with #{rows.count} rows, expected #{expected_table.count}" - - else + if rows.count == expected_table.count rows.each_with_index do |row, i| expected_row = expected_table[i] if row.count != expected_row.count @@ -52,6 +49,9 @@ RSpec::Matchers.define :match_table do |expected_table| break if @failure_message end end + else + @failure_message = "found table with #{rows.count} rows, expected #{expected_table.count}" + end @failure_message.nil? From 3c7c345534d5126209346c5d7eb5d5fe89b1a669 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Thu, 9 Nov 2023 09:37:45 +0900 Subject: [PATCH 3/6] Safely autocorrect Style/ParenthesesAroundCondition Inspecting 1509 files ......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.............. Offenses: spec/system/support/precompile_assets.rb:10:10: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected. next if ^ spec/system/support/precompile_assets.rb:10:11: C: [Corrected] Style/ParenthesesAroundCondition: Don't use parentheses around the condition of an if. next if ( ... ^ spec/system/support/precompile_assets.rb:13:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected. spec/system/support/precompile_assets.rb:14:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected. 1509 files inspected, 4 offenses detected, 4 offenses corrected --- .rubocop_todo.yml | 7 ------- spec/system/support/precompile_assets.rb | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 766c7a3275..1d4f9d01bf 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -907,13 +907,6 @@ Style/OptionalBooleanParameter: - 'lib/spree/core/controller_helpers/order.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. -Style/ParenthesesAroundCondition: - Exclude: - - 'spec/system/support/precompile_assets.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. diff --git a/spec/system/support/precompile_assets.rb b/spec/system/support/precompile_assets.rb index 2cf819cbf1..cb137f19e6 100644 --- a/spec/system/support/precompile_assets.rb +++ b/spec/system/support/precompile_assets.rb @@ -7,10 +7,9 @@ RSpec.configure do |config| # rspec --tag ~type:system # # In this case, we don't need to precompile assets. - next if ( + next if config.filter.opposite.rules[:type] == "system" || config.exclude_pattern.match?(%r{spec/system}) - ) config.before(:suite) do # We can use webpack-dev-server for tests, too! From ef928aa6fe8239c8af12d445ccab541bcbebd674 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Thu, 9 Nov 2023 09:39:05 +0900 Subject: [PATCH 4/6] Safely autocorrect Style/QuotedSymbols Inspecting 1509 files .....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.................................................................................................................................................................................................................................................................................................................................C............................................................C...........................................................................................................................................................................................................................................................................................................................................C.C.........................................................................................................................................C........................................................................................................................................ Offenses: app/services/exchange_products_renderer.rb:50:13: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. where("spree_variants.id": incoming_exchanges_variants) ^^^^^^^^^^^^^^^^^^^ lib/stripe/credit_card_cloner.rb:67:50: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. { metadata: { "ofn-clone": true } }, ^^^^^^^^^^^ spec/controllers/api/v0/exchange_products_controller_spec.rb:59:52: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. Spree::Product.includes(:variants).where("spree_variants.id": exchange.variants.map(&:id)) ^^^^^^^^^^^^^^^^^^^ spec/requests/api/orders_spec.rb:35:11: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. "application/json": { ^^^^^^^^^^^^^^^^^^ spec/requests/api/v1/customers_spec.rb:39:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/customers_collection" ^^^^^^ spec/requests/api/v1/customers_spec.rb:186:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/customer" ^^^^^^ spec/requests/api/v1/customers_spec.rb:207:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/customer" ^^^^^^ spec/requests/api/v1/customers_spec.rb:230:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/error_response" ^^^^^^ spec/requests/api/v1/customers_spec.rb:239:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/error_response" ^^^^^^ spec/requests/api/v1/customers_spec.rb:274:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/error_response" ^^^^^^ spec/requests/api/v1/customers_spec.rb:286:18: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/error_response" ^^^^^^ spec/requests/api/v1/customers_spec.rb:361:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/customer" ^^^^^^ spec/requests/api/v1/customers_spec.rb:427:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/error_response" ^^^^^^ spec/requests/api/v1/customers_spec.rb:440:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/customer" ^^^^^^ spec/requests/api/v1/customers_spec.rb:455:16: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. schema "$ref": "#/components/schemas/customers_collection" ^^^^^^ spec/support/request/stripe_stubs.rb:72:42: C: [Corrected] Style/QuotedSymbols: Prefer single-quoted symbols when you don't need string interpolation or special symbols. stub = stub.with(body: { metadata: { "ofn-clone": true } }) ^^^^^^^^^^^ 1509 files inspected, 16 offenses detected, 16 offenses corrected --- .rubocop_todo.yml | 13 ----------- app/services/exchange_products_renderer.rb | 2 +- lib/stripe/credit_card_cloner.rb | 2 +- .../v0/exchange_products_controller_spec.rb | 2 +- spec/requests/api/orders_spec.rb | 2 +- spec/requests/api/v1/customers_spec.rb | 22 +++++++++---------- spec/support/request/stripe_stubs.rb | 2 +- 7 files changed, 16 insertions(+), 29 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1d4f9d01bf..37b859d881 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -915,19 +915,6 @@ Style/PreferredHashMethods: Exclude: - 'app/controllers/api/v0/shipments_controller.rb' -# Offense count: 16 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: same_as_string_literals, single_quotes, double_quotes -Style/QuotedSymbols: - Exclude: - - 'app/services/exchange_products_renderer.rb' - - 'lib/stripe/credit_card_cloner.rb' - - 'spec/controllers/api/v0/exchange_products_controller_spec.rb' - - 'spec/requests/api/orders_spec.rb' - - 'spec/requests/api/v1/customers_spec.rb' - - 'spec/support/request/stripe_stubs.rb' - # Offense count: 3 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Methods. diff --git a/app/services/exchange_products_renderer.rb b/app/services/exchange_products_renderer.rb index 66217cd2ec..c6cfceab22 100644 --- a/app/services/exchange_products_renderer.rb +++ b/app/services/exchange_products_renderer.rb @@ -47,7 +47,7 @@ class ExchangeProductsRenderer def products_for_outgoing_exchange supplied_products(enterprises_for_outgoing_exchange.select(:id)). includes(:variants). - where("spree_variants.id": incoming_exchanges_variants) + where('spree_variants.id': incoming_exchanges_variants) end def incoming_exchanges_variants diff --git a/lib/stripe/credit_card_cloner.rb b/lib/stripe/credit_card_cloner.rb index 441efbe52a..465cc362b3 100644 --- a/lib/stripe/credit_card_cloner.rb +++ b/lib/stripe/credit_card_cloner.rb @@ -64,7 +64,7 @@ module Stripe def add_metadata_to_payment_method(payment_method_id) Stripe::PaymentMethod.update(payment_method_id, - { metadata: { "ofn-clone": true } }, + { metadata: { 'ofn-clone': true } }, stripe_account: @stripe_account) end end diff --git a/spec/controllers/api/v0/exchange_products_controller_spec.rb b/spec/controllers/api/v0/exchange_products_controller_spec.rb index 670d98902d..18c04f3825 100644 --- a/spec/controllers/api/v0/exchange_products_controller_spec.rb +++ b/spec/controllers/api/v0/exchange_products_controller_spec.rb @@ -56,7 +56,7 @@ module Api describe "pagination" do let(:exchange) { order_cycle.exchanges.outgoing.first } let(:products_relation) { - Spree::Product.includes(:variants).where("spree_variants.id": exchange.variants.map(&:id)) + Spree::Product.includes(:variants).where('spree_variants.id': exchange.variants.map(&:id)) } before do diff --git a/spec/requests/api/orders_spec.rb b/spec/requests/api/orders_spec.rb index 471b5a46e5..20ea82c530 100644 --- a/spec/requests/api/orders_spec.rb +++ b/spec/requests/api/orders_spec.rb @@ -32,7 +32,7 @@ describe 'api/v0/orders', swagger_doc: 'v0.yaml', type: :request do # Which would also validate the response in the test, this is an open # issue with rswag: https://github.com/rswag/rswag/issues/268 metadata[:response][:content] = { - "application/json": { + 'application/json': { schema: { '$ref' => '#/components/schemas/Order_Concise' } } } diff --git a/spec/requests/api/v1/customers_spec.rb b/spec/requests/api/v1/customers_spec.rb index 002651861a..a4032d26af 100644 --- a/spec/requests/api/v1/customers_spec.rb +++ b/spec/requests/api/v1/customers_spec.rb @@ -36,7 +36,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "200", "Customers list" do param(:enterprise_id) { enterprise1.id } param("extra_fields[customer]") { :balance } - schema "$ref": "#/components/schemas/customers_collection" + schema '$ref': "#/components/schemas/customers_collection" run_test! end @@ -183,7 +183,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do enterprise_id: enterprise1.id.to_s } end - schema "$ref": "#/components/schemas/customer" + schema '$ref': "#/components/schemas/customer" run_test! do expect(json_response[:data][:attributes]).to include( @@ -204,7 +204,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do enterprise_id: enterprise1.id, ) end - schema "$ref": "#/components/schemas/customer" + schema '$ref': "#/components/schemas/customer" run_test! do expect(json_response[:data][:attributes]).to include( @@ -227,7 +227,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do allow_charges: true, } end - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! do expect(json_error_detail).to eq "Parameters not allowed in this request: allow_charges" @@ -236,7 +236,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "422", "Unprocessable entity" do param(:customer) { {} } - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! do expect(json_error_detail).to eq "A required parameter is missing or empty: customer" @@ -271,7 +271,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "404", "Not found" do param(:id) { 0 } - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! do expect(json_error_detail).to eq "The resource you were looking for could not be found." @@ -283,7 +283,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "401", "Unauthorized" do param(:id) { customer1.id } - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! do expect(json_error_detail).to eq "You are not authorized to perform that action." @@ -358,7 +358,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do enterprise_id: enterprise1.id.to_s } end - schema "$ref": "#/components/schemas/customer" + schema '$ref': "#/components/schemas/customer" run_test! do # Tags should not be overridden when the param is missing: @@ -424,7 +424,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "422", "Unprocessable entity" do param(:id) { customer1.id } param(:customer) { {} } - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! end @@ -437,7 +437,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "200", "Customer deleted" do param(:id) { customer1.id } - schema "$ref": "#/components/schemas/customer" + schema '$ref': "#/components/schemas/customer" run_test! end @@ -452,7 +452,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "200", "Customers list" do param(:enterprise_id) { enterprise1.id } - schema "$ref": "#/components/schemas/customers_collection" + schema '$ref': "#/components/schemas/customers_collection" run_test! end diff --git a/spec/support/request/stripe_stubs.rb b/spec/support/request/stripe_stubs.rb index b2943741ca..9a10c9830a 100644 --- a/spec/support/request/stripe_stubs.rb +++ b/spec/support/request/stripe_stubs.rb @@ -69,7 +69,7 @@ module StripeStubs def stub_add_metadata_request(payment_method: "pm_456", response: {}) stub = stub_request(:post, "https://api.stripe.com/v1/payment_methods/#{payment_method}") - stub = stub.with(body: { metadata: { "ofn-clone": true } }) + stub = stub.with(body: { metadata: { 'ofn-clone': true } }) stub = stub.with( headers: { 'Stripe-Account' => 'abc123' } ) From c3b4781a287383cf0e49d0c86b87223853f25605 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Thu, 9 Nov 2023 09:40:29 +0900 Subject: [PATCH 5/6] Safely autocorrect Style/RedundantConstantBase Inspecting 1509 files .........................................................................................................C.........................................C......................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.......................................................................................................................................................................................................................................................................................................................................................................................................................C.........................................................................................................................................................................CCC........................................C......................................................................................C...................................................................................................................................................................................................... Offenses: app/controllers/split_checkout_controller.rb:5:33: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. class SplitCheckoutController < ::BaseController ^^ app/controllers/webhook_endpoints_controller.rb:3:36: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. class WebhookEndpointsController < ::BaseController ^^ config.ru:5:9: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. require ::File.expand_path('config/environment', __dir__) ^^ spec/helpers/checkout_helper_spec.rb:168:68: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. let!(:tax_rate) { create(:tax_rate, amount: 0.1, calculator: ::Calculator::DefaultTax.new) } ^^ spec/models/spree/order_spec.rb:619:25: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. let(:fee_handler) { ::OrderFeesHandler.new(subject) } ^^ spec/models/spree/payment_method_spec.rb:150:51: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. calculator: ::Calculator::FlatRate.new(preferred_amount: 10)) ^^ spec/models/spree/payment_method_spec.rb:154:54: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. calculator: ::Calculator::FlatPercentItemTotal ^^ spec/models/spree/payment_spec.rb:429:49: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. create(:payment_method, calculator: ::Calculator::FlatRate.new(preferred_amount: 10)) ^^ spec/models/spree/payment_spec.rb:1002:11: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) ^^ spec/models/spree/payment_spec.rb:1039:28: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. let(:calculator) { ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) } ^^ spec/queries/complete_visible_orders_spec.rb:12:31: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. let(:order_permissions) { ::Permissions::Order.new(user, filter_canceled) } ^^ spec/services/paypal_items_builder_spec.rb:34:37: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. calculator: ::Calculator::DefaultTax.new) ^^ spec/services/paypal_items_builder_spec.rb:38:37: C: [Corrected] Style/RedundantConstantBase: Remove redundant ::. calculator: ::Calculator::DefaultTax.new) ^^ 1509 files inspected, 13 offenses detected, 13 offenses corrected --- .rubocop_todo.yml | 14 -------------- app/controllers/split_checkout_controller.rb | 2 +- app/controllers/webhook_endpoints_controller.rb | 2 +- config.ru | 2 +- spec/helpers/checkout_helper_spec.rb | 2 +- spec/models/spree/order_spec.rb | 2 +- spec/models/spree/payment_method_spec.rb | 4 ++-- spec/models/spree/payment_spec.rb | 6 +++--- spec/queries/complete_visible_orders_spec.rb | 2 +- spec/services/paypal_items_builder_spec.rb | 4 ++-- 10 files changed, 13 insertions(+), 27 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 37b859d881..65caf81752 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -923,20 +923,6 @@ Style/RedundantArgument: - 'engines/dfc_provider/app/services/authorization_control.rb' - 'spec/support/query_counter.rb' -# Offense count: 13 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantConstantBase: - Exclude: - - 'app/controllers/split_checkout_controller.rb' - - 'app/controllers/webhook_endpoints_controller.rb' - - 'config.ru' - - 'spec/helpers/checkout_helper_spec.rb' - - 'spec/models/spree/order_spec.rb' - - 'spec/models/spree/payment_method_spec.rb' - - 'spec/models/spree/payment_spec.rb' - - 'spec/queries/complete_visible_orders_spec.rb' - - 'spec/services/paypal_items_builder_spec.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Style/RedundantDoubleSplatHashBraces: diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 9bcd6a709e..36d17ddfe5 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -2,7 +2,7 @@ require 'open_food_network/address_finder' -class SplitCheckoutController < ::BaseController +class SplitCheckoutController < BaseController layout 'darkswarm' include OrderStockCheck diff --git a/app/controllers/webhook_endpoints_controller.rb b/app/controllers/webhook_endpoints_controller.rb index c9493f42bb..44580391de 100644 --- a/app/controllers/webhook_endpoints_controller.rb +++ b/app/controllers/webhook_endpoints_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class WebhookEndpointsController < ::BaseController +class WebhookEndpointsController < BaseController before_action :load_resource, only: :destroy def create diff --git a/config.ru b/config.ru index b834259514..c5850bfca6 100644 --- a/config.ru +++ b/config.ru @@ -2,5 +2,5 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('config/environment', __dir__) +require File.expand_path('config/environment', __dir__) run Openfoodnetwork::Application diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb index f52b611d9b..9aae5df87a 100644 --- a/spec/helpers/checkout_helper_spec.rb +++ b/spec/helpers/checkout_helper_spec.rb @@ -165,7 +165,7 @@ describe CheckoutHelper, type: :helper do end context "tax rate adjustments" do - let!(:tax_rate) { create(:tax_rate, amount: 0.1, calculator: ::Calculator::DefaultTax.new) } + let!(:tax_rate) { create(:tax_rate, amount: 0.1, calculator: Calculator::DefaultTax.new) } let!(:line_item_fee_adjustment) { create(:adjustment, originator: enterprise_fee, adjustable: order.line_items.first, order:) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index b2544ce910..030eb3704f 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -616,7 +616,7 @@ describe Spree::Order do describe "applying enterprise fees" do subject { create(:order) } - let(:fee_handler) { ::OrderFeesHandler.new(subject) } + let(:fee_handler) { OrderFeesHandler.new(subject) } before do allow(subject).to receive(:fee_handler) { fee_handler } diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb index e3a72dcb28..634ed0d672 100644 --- a/spec/models/spree/payment_method_spec.rb +++ b/spec/models/spree/payment_method_spec.rb @@ -147,11 +147,11 @@ describe Spree::PaymentMethod do expect(free_payment_method.compute_amount(order)).to eq 0 flat_rate_payment_method = create(:payment_method, - calculator: ::Calculator::FlatRate.new(preferred_amount: 10)) + calculator: Calculator::FlatRate.new(preferred_amount: 10)) expect(flat_rate_payment_method.compute_amount(order)).to eq 10 flat_percent_payment_method = create(:payment_method, - calculator: ::Calculator::FlatPercentItemTotal + calculator: Calculator::FlatPercentItemTotal .new(preferred_flat_percent: 10)) expect(flat_percent_payment_method.compute_amount(order)).to eq 0 diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 229af6342c..ff3edfce60 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -426,7 +426,7 @@ describe Spree::Payment do context "if payment has any adjustment" do let!(:order) { create(:order) } let!(:payment_method) { - create(:payment_method, calculator: ::Calculator::FlatRate.new(preferred_amount: 10)) + create(:payment_method, calculator: Calculator::FlatRate.new(preferred_amount: 10)) } it "should create another adjustment and revoke the previous one" do @@ -999,7 +999,7 @@ describe Spree::Payment do let!(:shop) { create(:enterprise) } let!(:payment_method) { create(:payment_method, calculator:) } let!(:calculator) do - ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) + Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) end context "when order complete" do @@ -1036,7 +1036,7 @@ describe Spree::Payment do let(:payment) { create(:payment, order:, payment_method:, amount: order.total) } - let(:calculator) { ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) } + let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) } before do payment_method.calculator = calculator diff --git a/spec/queries/complete_visible_orders_spec.rb b/spec/queries/complete_visible_orders_spec.rb index 82f66093ff..2018674338 100644 --- a/spec/queries/complete_visible_orders_spec.rb +++ b/spec/queries/complete_visible_orders_spec.rb @@ -9,7 +9,7 @@ describe CompleteVisibleOrders do describe '#query' do let(:user) { create(:user) } let(:enterprise) { create(:enterprise) } - let(:order_permissions) { ::Permissions::Order.new(user, filter_canceled) } + let(:order_permissions) { Permissions::Order.new(user, filter_canceled) } before do user.enterprises << enterprise diff --git a/spec/services/paypal_items_builder_spec.rb b/spec/services/paypal_items_builder_spec.rb index c60b2bf8ac..227422b612 100644 --- a/spec/services/paypal_items_builder_spec.rb +++ b/spec/services/paypal_items_builder_spec.rb @@ -31,11 +31,11 @@ describe PaypalItemsBuilder do let!(:zone) { create(:zone_with_member) } let!(:included_tax_rate) { create(:tax_rate, amount: 12, included_in_price: true, zone:, - calculator: ::Calculator::DefaultTax.new) + calculator: Calculator::DefaultTax.new) } let!(:additional_tax_rate) { create(:tax_rate, amount: 34, included_in_price: false, zone:, - calculator: ::Calculator::DefaultTax.new) + calculator: Calculator::DefaultTax.new) } let!(:included_tax_adjustment) { create(:adjustment, label: "Included Tax Adjustment", order:, From 7c14853add713f930942e167a13b82823b7e06d1 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Thu, 9 Nov 2023 09:42:14 +0900 Subject: [PATCH 6/6] Safely autocorrect Style/RedundantDoubleSplatHashBraces Inspecting 1509 files .....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C............... Offenses: spec/system/support/cuprite_setup.rb:13:5: C: [Corrected] Style/RedundantDoubleSplatHashBraces: Remove the redundant double splat and braces, use keyword arguments directly. **{ ... ^^^ spec/system/support/cuprite_setup.rb:14:7: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line. browser_options:, ^^^^^^^^^^^^^^^^ spec/system/support/cuprite_setup.rb:15:7: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line. process_timeout: 60, ^^^^^^^^^^^^^^^^^^^ spec/system/support/cuprite_setup.rb:16:7: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line. timeout: 60, ^^^^^^^^^^^ spec/system/support/cuprite_setup.rb:17:7: C: [Corrected] Layout/CommentIndentation: Incorrect indentation detected (column 6 instead of 4). # Don't load scripts from external sources, like google maps or stripe ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/support/cuprite_setup.rb:18:7: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line. url_whitelist: ["http://localhost", "http://0.0.0.0", "http://127.0.0.1"], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/support/cuprite_setup.rb:19:7: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line. inspector: true, ^^^^^^^^^^^^^^^ spec/system/support/cuprite_setup.rb:20:7: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line. headless:, ^^^^^^^^^ spec/system/support/cuprite_setup.rb:21:7: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line. js_errors: true ^^^^^^^^^^^^^^^ 1509 files inspected, 9 offenses detected, 9 offenses corrected --- .rubocop_todo.yml | 6 ------ spec/system/support/cuprite_setup.rb | 20 +++++++++----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 65caf81752..44eff7c575 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -923,12 +923,6 @@ Style/RedundantArgument: - 'engines/dfc_provider/app/services/authorization_control.rb' - 'spec/support/query_counter.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantDoubleSplatHashBraces: - Exclude: - - 'spec/system/support/cuprite_setup.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowComments. diff --git a/spec/system/support/cuprite_setup.rb b/spec/system/support/cuprite_setup.rb index d3d5cd06c1..9d89e05634 100644 --- a/spec/system/support/cuprite_setup.rb +++ b/spec/system/support/cuprite_setup.rb @@ -10,17 +10,15 @@ browser_options["no-sandbox"] = nil if ENV['CI'] Capybara.register_driver(:cuprite_ofn) do |app| Capybara::Cuprite::Driver.new( app, - **{ - window_size: [1280, 800], - browser_options:, - process_timeout: 60, - timeout: 60, - # Don't load scripts from external sources, like google maps or stripe - url_whitelist: ["http://localhost", "http://0.0.0.0", "http://127.0.0.1"], - inspector: true, - headless:, - js_errors: true, - } + window_size: [1280, 800], + browser_options:, + process_timeout: 60, + timeout: 60, + # Don't load scripts from external sources, like google maps or stripe + url_whitelist: ["http://localhost", "http://0.0.0.0", "http://127.0.0.1"], + inspector: true, + headless:, + js_errors: true ) end