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 #1283] Mark WhereRange as unsafe autocorrect #1293

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

fatkodima
Copy link
Contributor

Fixes #1283.

Copy link

@mark-young-atg mark-young-atg left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks @fatkodima

@koic
Copy link
Member

koic commented Jun 10, 2024

Can you update instances where joins(:events) is used with where('end_at < ?', Time.zone.now) as shown below to be corrected to where(events: { end_at: ...Time.zone.now })?

From:

joins(:events).where('end_at < ?', Time.zone.now)

To:

joins(:events).where(events: { end_at: ...Time.zone.now })

While it makes sense for SafeAutoCorrect: false in general, in the case of #1283, it seems it can first be provided as a safe autocorrection:

@fatkodima
Copy link
Contributor Author

This is not a right suggestion, because if the column is on the top level table and we use joins, suggesting joins(:events).where(events: { end_at: ...Time.zone.now }) now incorrectly attaches column to the wrong table.

So I would just mark this cop as unsafe autocorrect and not to try be smart here, because it will not work out.

@koic
Copy link
Member

koic commented Jun 10, 2024

Ah, OK. Can you add example code to the @safety section and provide a bit more detail?

@koic
Copy link
Member

koic commented Jun 10, 2024

Since it is not false positive but unsafe autocorrection, ideally, it would be preferable to provide example that allows users to manually correct to the right autocorrection 😃

@fatkodima
Copy link
Contributor Author

Added an example to the @safety section.

@koic
Copy link
Member

koic commented Jun 10, 2024

Thanks 👍

@koic koic merged commit 202d8c1 into rubocop:master Jun 10, 2024
14 checks passed
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.

Safe-autocorrect with Rails/WhereRange does not work correctly when
3 participants