Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autocorrect Rails Cops 2 #11337

Merged
merged 6 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 10 additions & 55 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -449,24 +449,6 @@ Rails/CompactBlank:
- 'lib/reporting/report_ruler.rb'
- 'lib/reporting/reports/enterprise_fee_summary/parameters.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Rails/ExpandedDateRange:
Exclude:
- 'app/models/spree/product.rb'

# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: slashes, arguments
Rails/FilePath:
Exclude:
- 'app/models/product_import/product_importer.rb'
- 'lib/tasks/karma.rake'
- 'spec/base_spec_helper.rb'
- 'spec/models/content_configuration_spec.rb'
- 'spec/support/downloads_helper.rb'

# Offense count: 8
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Expand Down Expand Up @@ -520,14 +502,6 @@ Rails/HelperInstanceVariable:
- 'app/helpers/spree/admin/orders_helper.rb'
- 'app/helpers/spree/orders_helper.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include.
# Include: app/controllers/**/*.rb
Rails/I18nLazyLookup:
Exclude:
- 'app/controllers/admin/proxy_orders_controller.rb'

# Offense count: 8
# Configuration parameters: Include.
# Include: spec/**/*.rb, test/**/*.rb
Expand Down Expand Up @@ -671,6 +645,7 @@ 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'
Expand Down Expand Up @@ -701,30 +676,14 @@ Rails/ResponseParsedBody:
- 'spec/controllers/spree/credit_cards_controller_spec.rb'
- 'spec/controllers/user_registrations_controller_spec.rb'

# Offense count: 4
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/RootPathnameMethods:
Exclude:
- 'spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb'
- 'spec/models/content_configuration_spec.rb'
- 'spec/models/terms_of_service_file_spec.rb'
- 'spec/system/admin/configuration/terms_of_service_files_spec.rb'

# Offense count: 13
# This cop supports safe autocorrection (--autocorrect).
Rails/RootPublicPath:
Exclude:
- 'app/controllers/concerns/request_timeouts.rb'
- 'lib/spree/core/controller_helpers/common.rb'
- 'spec/controllers/api/v0/product_images_controller_spec.rb'
- 'spec/controllers/api/v0/terms_and_conditions_controller_spec.rb'
- 'spec/models/terms_of_service_file_spec.rb'
- 'spec/system/admin/bulk_product_update_spec.rb'
- 'spec/system/admin/enterprises/terms_and_conditions_spec.rb'
- 'spec/system/consumer/shopping/checkout_spec.rb'
- 'spec/system/consumer/shopping/embedded_groups_spec.rb'
- 'spec/system/consumer/split_checkout_spec.rb'

# Offense count: 4
# Configuration parameters: ForbiddenMethods, AllowedMethods.
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
Expand All @@ -741,16 +700,6 @@ Rails/SquishedSQLHeredocs:
- 'app/queries/outstanding_balance.rb'
- 'spec/queries/outstanding_balance_spec.rb'

# Offense count: 24
# This cop supports safe autocorrection (--autocorrect).
Rails/StripHeredoc:
Exclude:
- 'app/models/content_configuration.rb'
- 'app/queries/customers_with_balance.rb'
- 'app/queries/outstanding_balance.rb'
- 'lib/reporting/reports/enterprise_fee_summary/scope.rb'
- 'lib/tasks/data/truncate_data.rake'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
Expand Down Expand Up @@ -1530,14 +1479,13 @@ Style/RedundantArgument:
- 'engines/dfc_provider/app/services/authorization_control.rb'
- 'spec/support/query_counter.rb'

# Offense count: 14
# 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/base_spec_helper.rb'
- 'spec/helpers/checkout_helper_spec.rb'
- 'spec/models/spree/order_spec.rb'
- 'spec/models/spree/payment_method_spec.rb'
Expand All @@ -1558,6 +1506,13 @@ Style/RedundantInitialize:
Exclude:
- 'spec/models/spree/gateway_spec.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/RedundantInterpolation:
Exclude:
- 'lib/tasks/karma.rake'
- 'spec/base_spec_helper.rb'
Comment on lines +1509 to +1514
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been addressed in the previous commit which introduced these.


# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpArgument:
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/proxy_orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def cancel
if @proxy_order.cancel
render_as_json @proxy_order
else
render json: { errors: [t('admin.proxy_orders.cancel.could_not_cancel_the_order')] },
render json: { errors: [t('.could_not_cancel_the_order')] },
status: :unprocessable_entity
end
end
Expand All @@ -22,7 +22,7 @@ def resume
if @proxy_order.resume
render_as_json @proxy_order
else
render json: { errors: [t('admin.proxy_orders.resume.could_not_resume_the_order')] },
render json: { errors: [t('.could_not_resume_the_order')] },
status: :unprocessable_entity
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/request_timeouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def timeout_response(_exception = nil)
respond_to do |type|
type.html {
render status: :gateway_timeout,
file: Rails.root.join("public/500.html"),
file: Rails.public_path.join('500.html'),
formats: [:html],
layout: nil
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/content_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ContentConfiguration < Spree::Preferences::Configuration
preference :footer_pinterest_url, :string, default: ""
preference :footer_email, :string, default: "[email protected]"
preference :community_forum_url, :string, default: "http://community.openfoodnetwork.org"
preference :footer_links_md, :text, default: <<-EOS.strip_heredoc
preference :footer_links_md, :text, default: <<~EOS
[Newsletter sign-up](/)

[News](/)
Expand Down
2 changes: 1 addition & 1 deletion app/models/product_import/product_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def save_all_valid
end

def delete_uploaded_file
return unless @file.path == Rails.root.join('tmp', 'product_import').to_s
return unless @file.path == Rails.root.join("tmp/product_import").to_s

File.delete(@file)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Product < ApplicationRecord
import_date = Time.zone.parse import_date if import_date.is_a? String
import_date = import_date.to_date
joins(:variants).merge(Spree::Variant.
where(import_date: import_date.beginning_of_day..import_date.end_of_day))
where(import_date: import_date.all_day))
}

scope :with_order_cycles_inner, -> {
Expand Down
2 changes: 1 addition & 1 deletion app/queries/customers_with_balance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def query
# The resulting orders are in states that belong after the checkout. Only these can be considered
# for a customer's balance.
def left_join_complete_orders
<<-SQL.strip_heredoc
<<~SQL
LEFT JOIN spree_orders ON spree_orders.customer_id = customers.id
AND #{finalized_states.to_sql}
SQL
Expand Down
2 changes: 1 addition & 1 deletion app/queries/outstanding_balance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def query
# Arel doesn't support CASE statements until v7.1.0 so we'll have to wait with SQL literals
# a little longer. See https://github.com/rails/arel/pull/400 for details.
def statement
<<-SQL.strip_heredoc
<<~SQL
CASE WHEN "spree_orders"."state" IN #{non_fulfilled_states_group.to_sql} THEN "spree_orders"."payment_total"
WHEN "spree_orders"."state" IS NOT NULL THEN "spree_orders"."payment_total" - "spree_orders"."total"
ELSE 0 END
Expand Down
40 changes: 20 additions & 20 deletions lib/reporting/reports/enterprise_fee_summary/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def for_supported_adjustments

def include_adjustment_metadata
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN adjustment_metadata
ON (adjustment_metadata.adjustment_id = spree_adjustments.id)
JOIN_STRING
Expand All @@ -81,7 +81,7 @@ def include_adjustment_metadata
# * Hub
def include_order_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_orders
ON (
spree_orders.id = spree_adjustments.order_id
Expand All @@ -93,7 +93,7 @@ def include_order_details
join_scope("LEFT OUTER JOIN customers ON (customers.id = spree_orders.customer_id)")

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS hubs
ON (hubs.id = spree_orders.distributor_id)
JOIN_STRING
Expand All @@ -106,7 +106,7 @@ def include_order_details
# * Payment method
def include_payment_fee_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_payment_methods
ON (
spree_adjustments.originator_type = 'Spree::PaymentMethod'
Expand All @@ -116,7 +116,7 @@ def include_payment_fee_details
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS payment_hubs
ON (
spree_payment_methods.id IS NOT NULL
Expand All @@ -132,7 +132,7 @@ def include_payment_fee_details
# * Shipping method
def include_shipping_fee_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_shipping_methods
ON (
spree_adjustments.originator_type = 'Spree::ShippingMethod'
Expand All @@ -148,7 +148,7 @@ def include_shipping_fee_details
# * Enterprise fee tax category
def include_enterprise_fee_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprise_fees
ON (
spree_adjustments.originator_type = 'EnterpriseFee'
Expand All @@ -158,14 +158,14 @@ def include_enterprise_fee_details
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises
ON (enterprises.id = enterprise_fees.enterprise_id)
JOIN_STRING
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_tax_categories
ON (spree_tax_categories.id = enterprise_fees.tax_category_id)
JOIN_STRING
Expand All @@ -179,7 +179,7 @@ def include_enterprise_fee_details
# * Distributor
def include_order_source_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_orders AS adjustment_source_orders
ON (
spree_adjustments.adjustable_type = 'Spree::Order'
Expand All @@ -189,7 +189,7 @@ def include_order_source_details
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS adjustment_source_distributors
ON (adjustment_source_distributors.id = adjustment_source_orders.distributor_id)
JOIN_STRING
Expand All @@ -205,7 +205,7 @@ def include_order_source_details
# * Tax category of product, if enterprise fee tells to inherit
def include_line_item_source_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_line_items
ON (
spree_adjustments.adjustable_type = 'Spree::LineItem'
Expand All @@ -215,7 +215,7 @@ def include_line_item_source_details
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_variants
ON (
spree_adjustments.adjustable_type = 'Spree::LineItem'
Expand All @@ -225,14 +225,14 @@ def include_line_item_source_details
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_products
ON (spree_products.id = spree_variants.product_id)
JOIN_STRING
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_tax_categories AS product_tax_categories
ON (
enterprise_fees.inherits_tax_category IS TRUE
Expand All @@ -250,7 +250,7 @@ def include_line_item_source_details
# * Incoming exchange variant
def include_incoming_exchange_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN
(
exchange_variants AS incoming_exchange_variants
Expand All @@ -271,7 +271,7 @@ def include_incoming_exchange_details
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS incoming_exchange_enterprises
ON (incoming_exchange_enterprises.id = incoming_exchanges.sender_id)
JOIN_STRING
Expand All @@ -286,7 +286,7 @@ def include_incoming_exchange_details
# * Outgoing exchange variant
def include_outgoing_exchange_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN
(
exchange_variants AS outgoing_exchange_variants
Expand All @@ -307,7 +307,7 @@ def include_outgoing_exchange_details
)

join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS outgoing_exchange_enterprises
ON (outgoing_exchange_enterprises.id = outgoing_exchanges.receiver_id)
JOIN_STRING
Expand Down Expand Up @@ -366,7 +366,7 @@ def group_data
def select_attributes
chain_to_scope do
select(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
SUM(spree_adjustments.amount) AS total_amount,
spree_payment_methods.name AS payment_method_name,
spree_shipping_methods.name AS shipping_method_name,
Expand Down
2 changes: 1 addition & 1 deletion lib/spree/core/controller_helpers/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def render_404(_exception = nil)
respond_to do |type|
type.html {
render status: :not_found,
file: Rails.root.join("public/404.html"),
file: Rails.public_path.join('404.html'),
formats: [:html],
layout: nil
}
Expand Down
Loading