Skip to content

Fix linting errors #6240

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

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

Fix linting errors #6240

wants to merge 25 commits into from

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented May 28, 2025

Summary

This fixes the linting errors introduced by yet another release of Rubocop.

I've chosen to actually do the inverse_of/dependent dance because it does improve the software.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

@mamhoff mamhoff requested a review from a team as a code owner May 28, 2025 16:25
@github-actions github-actions bot added changelog:solidus_api Changes to the solidus_api gem changelog:solidus_core Changes to the solidus_core gem changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem changelog:solidus_promotions Changes to the solidus_promotions gem labels May 28, 2025
@mamhoff mamhoff force-pushed the fix-linting-errors branch from cb337c8 to 998621e Compare May 28, 2025 16:28
@tvdeyen tvdeyen mentioned this pull request May 28, 2025
4 tasks
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

WOW 😲

Many great things in here, BUT "Fix linting errors" is an understatement 🤣

Most of these changes warrant a dedicated PR.

-> { includes(:credit_type) },
foreign_key: "user_id",
class_name: "Spree::StoreCredit",
dependent: :nullify,
Copy link
Member

Choose a reason for hiding this comment

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

I would be totally fine for deactivated users to actually lose their store credit as well, but since store credit might be used for past payments as source we cannot do that, is that right?

@@ -26,7 +26,8 @@ class BaseController < ActionController::Base
before_action :load_user
before_action :authorize_for_order, if: proc { order_token.present? }
before_action :authenticate_user
before_action :load_user_roles
# This is deprecated and will be removed in Spree 5.0
before_action :load_deprecated_user_roles
Copy link
Member

Choose a reason for hiding this comment

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

This is a really great change. I would like that to appear as it's own PR in the changelog, though.

attr_accessor :current_api_user

before_action :load_user
before_action :deprecated_load_user
Copy link
Member

Choose a reason for hiding this comment

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

This as well is a really great change. I would like that to appear as it's own PR in the changelog, though.

foreign_key: "user_id",
class_name: "Spree::Order",
inverse_of: :user,
dependent: :nullify
Copy link
Member

Choose a reason for hiding this comment

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

This change is also very welcome, but warrants its own PR.

@@ -2,7 +2,7 @@

module Spree
class AdjustmentReason < Spree::Base
has_many :adjustments, inverse_of: :adjustment_reason
has_many :adjustments, inverse_of: :adjustment_reason, dependent: :restrict_with_exception
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about using restrict_with_error instead? So that we can display the error message on the record we try do delete instead of rendering a 500 in the admin. Otherwise we would need to rescue_from ActiveRecord::DeleteRestrictionError in the backend.

belongs_to :reimbursement, inverse_of: :refunds, optional: true

has_many :log_entries, as: :source
has_many :log_entries, as: :source, dependent: :destroy
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about this 🤔 . Actually I do not think refunds should ever be allowed to be destroyed. They are kind of legal records. I know that this just makes sure that if we delete a refund the log entry is removed as well, but I am not so sure about this as well.

@@ -13,9 +13,6 @@ class Taxon < Spree::Base
has_many :classifications, -> { order(:position) }, dependent: :delete_all, inverse_of: :taxon
has_many :products, through: :classifications

has_many :promotion_rule_taxons
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 be a separate PR, so we can back port it.

@@ -347,6 +347,10 @@ Rails/FindEach:
Exclude:
- "db/migrate/**/*"

Rails/LexicallyScopedActionFilter:
Exclude:
- "backend/app/controllers/**/*"
Copy link
Member

Choose a reason for hiding this comment

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

Why not remove the empty useless methods instead?

@@ -15,7 +15,7 @@ def check_for_constant
klass
rescue NameError
@shell.say "Couldn't find #{class_name}. Are you sure that this class exists within your application and is loaded?", :red
exit(1)
exit(1) # rubocop: disable Rails/Exit
Copy link
Member

Choose a reason for hiding this comment

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

abort is probably a better way of exiting in a generator?

@jarednorman
Copy link
Member

I looked through my notifications starting from the most recent. I was wondering where all these excellent little changes from @mamhoff came from... and now I know.

mamhoff added 11 commits July 2, 2025 10:52
I've opted for dependent: :destroy for records that do not need to be
saved for posterity in the scenario of completed orders, and for
:nullify if those records do need to be saved.
We should not delete adjustment reasons if there are adjustments created
with them.
We already have a `before_save` callback that runs
`inventory_units.destroy_all`. In order to save us all testing whether
adding `dependent: :destroy` would be a subtle change in behavior, I
just set the dependent: behavior to `false`.
I opted for `dependent: false` for addresses, because Spree::Address
records are immutable and therefore one user's address might give
another user's orders, which would be strange (also Spree::Address, for
this reason, does not have an `orders` association).

`valid_store_credit_payments` can have a dependent: :destroy just like
normal payments in the line above.

Orders that have reimbursement should not be able to be destroyed,
because semantically that can only happen once they have shipped.
If there are payments associated with the payment method, we can't just
destroy them. We could :nullify, but I prefer that an error is raised
and eventually handled.
When a payment is actually deleted, we should destroy the records that
belong to it as well. This is very rarely the case, payments mostly get
invalidated instead.
mamhoff added 14 commits July 2, 2025 10:52
When a permission set is destroyed, the join table entries to
spree_roles should also be destroyed.
Stock locations with cartons or shipments should not be destroyed, but
rather set to "inactive".
This adds dependent: x options to models related to store credits.
For join tables, dependent: :destroy is right. For orders, we restrict
with an error - otherwise they orders would silently reassociate to the
default store on the next save, which is probably not what stores want.
We should not delete tax rates that have adjustments. Otherwise we end
up with invalid data on adjustments, or even adjustments changing their
type, which would be BAD.
This cop wants us to write
```
def edit; super; end
```

This, in turn, wakes another cop "Useless method definition".
We do this all the time, and it's really time-consuming to fix. Also, no
clear benefit.
@mamhoff mamhoff force-pushed the fix-linting-errors branch from e1dc7b6 to 52605d6 Compare July 2, 2025 08:52
@github-actions github-actions bot removed changelog:solidus_api Changes to the solidus_api gem changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem changelog:solidus_promotions Changes to the solidus_promotions gem labels Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants