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

Add new Solidus/SpreeDefaultAddressDeprecated cop #64

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

the-krg
Copy link
Collaborator

@the-krg the-krg commented Nov 7, 2023

Description

Add a new cop that checks if user.default_address or user.default_user_address are being used, and warns user to change to user.ship_address or user.default_user_ship_address instead.


Severity:

  • - info
  • - refactor
  • - convention (default)
  • - warning
  • - error
  • - fatal

Wrong Code

      user.default_address
      user.default_user_address

Correct Code

      user.ship_address
      user.default_user_ship_address

Solidus PR Link: solidusio/solidus#3563


Before submitting the PR make sure the following are checked:

  • The PR relates to only one cop with a clear title and description.
  • Feature branch is up-to-date with main (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran and ensured all tests are passing on a development environment.
  • If this is a new cop, added an entry for the cop on /config/default.yml
  • Updated Changelog

@the-krg the-krg force-pushed the the-krg/add-default-address-deprecated-cop branch 6 times, most recently from e7f1f32 to 8af53ee Compare November 14, 2023 05:39
@the-krg the-krg marked this pull request as ready for review November 14, 2023 05:41
Copy link
Contributor

@piyushswain piyushswain left a comment

Choose a reason for hiding this comment

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

Just left a question on the cop.
If there has been a decision that no autocorrection should be done in the cops then it looks good.

def on_send(node)
return unless default_address?(node) || default_user_address?(node)

add_offense(node)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a corrector here to add some autocomplete to this cop as well ?

Seems like we can replace the violation with ship_address or default_user_ship_address in the corrector here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! Added!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for being late on this. Since this cop just raises a warning, maybe it is better not to use the autocorrection. WDYT? cc @safafa @DanielePalombo

Copy link
Contributor

Choose a reason for hiding this comment

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

The PR description mentions that this raises a default offense and also the code looks like it raises an offense rather than a warning.
Hence, raised the question here. @MassimilianoLattanzio

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right. It was neither specified in the relative issue. BTW, in our planning, we decided that maybe for too generic cops, it is better to raise a warning instead of an error.

Comment on lines 37 to 39
add_offense(node) do |corrector|
corrector.replace(node, node.source.gsub('default_address', 'ship_address')) if default_address?(node)
corrector.replace(node, node.source.gsub('default_user_address', 'default_user_ship_address')) if default_user_address?(node)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should extend AutoCorrector since you're calling corrector.replace here

Solidus/SpreeDefaultAddressDeprecated:
Description: 'Checks if user.default_address or user.default_user_address is used and suggest using user.ship_address or user.default_user_ship_address'
Enabled: true
VersionAdded: '0.1'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of specifying the version here, it's better to have the '<<next>>' string and then run the cut_release rake task as mentioned in the readme. In this way, we can also deploy a new version on GH and Rubygems.

@the-krg the-krg force-pushed the the-krg/add-default-address-deprecated-cop branch from 0160bf3 to 6245e36 Compare March 6, 2024 01:33
@the-krg
Copy link
Collaborator Author

the-krg commented Mar 6, 2024

Sorry, I'm late on this. Update with the latest suggestions, so we can merge or close it!
If we don't want a 0.3.0 release, just let me know and I'll keep it as <<next>>.

@MassimilianoLattanzio
Copy link
Collaborator

Sorry, I'm late on this. Update with the latest suggestions, so we can merge or close it! If we don't want a 0.3.0 release, just let me know and I'll keep it as <<next>>.

Hey Enzo, thanks for the update. ATM, we paused working on this. As soon as we will restart working on it, I'll review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants