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

Check for or method in Rails/FindEach cop #995

Merged
merged 1 commit into from
May 2, 2023

Conversation

masato-bkn
Copy link
Contributor

@masato-bkn masato-bkn commented Apr 30, 2023

This PR adds or method to the list of check methods in Rails/FindEach cop. Since the cop already checks for the use of where and not, I thought it would be better to include or as well.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • [-] Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • [-] If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@masato-bkn masato-bkn force-pushed the improve_rails_find_each branch from 936eba0 to 5d79903 Compare April 30, 2023 06:17
Comment on lines 37 to 38
all eager_load includes joins left_joins left_outer_joins not preload
references unscoped where
references unscoped where or
Copy link
Member

@koic koic May 2, 2023

Choose a reason for hiding this comment

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

Can you update to order by ASCII position?

-          all eager_load includes joins left_joins left_outer_joins not preload
-          references unscoped where or
+          all eager_load includes joins left_joins left_outer_joins not or preload
+          references unscoped where

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it!

@@ -33,6 +33,7 @@
it_behaves_like('register_offense', 'unscoped')
it_behaves_like('register_offense', 'where(name: name)')
it_behaves_like('register_offense', 'where.not(name: name)')
it_behaves_like('register_offense', 'where(name: name).or(User.where(age: age))')
Copy link
Member

Choose a reason for hiding this comment

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

Can you move to between L30 (left_outer_joins) and L31 (preload)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it!.

Copy link
Contributor Author

@masato-bkn masato-bkn May 2, 2023

Choose a reason for hiding this comment

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

https://github.com/rubocop/rubocop-rails/pull/995/files#diff-8b9e38f28a7bdb108efab88f1f3495067c22717be7973a6c73e92d5b0f599287L35
If you want to maintain order defined in SCOPE_METHODS, should I move this between left_outer_joins and or?

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave the existing one in favor of keeping git blame. Thank you.

@masato-bkn masato-bkn force-pushed the improve_rails_find_each branch from 5d79903 to bf38577 Compare May 2, 2023 05:26
@koic koic merged commit 585ddf1 into rubocop:master May 2, 2023
@koic
Copy link
Member

koic commented May 2, 2023

Thanks!

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.

2 participants