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

find_by_token_for and Rails/DynamicFindBy #781

Closed
strobilomyces opened this issue Sep 19, 2022 · 0 comments · Fixed by #783
Closed

find_by_token_for and Rails/DynamicFindBy #781

strobilomyces opened this issue Sep 19, 2022 · 0 comments · Fixed by #783

Comments

@strobilomyces
Copy link

Context

rails/rails#44189 introduced a token generator and a lookup function called find_by_token_for

rubocop-rails confuses it for a model lookup and is not pleased.

I originally posted about this in rails/rails#46065 and was told this is a rubocop-rails issue, so here we are.

Expected behavior

No violations detected.

Actual behavior

C: Rails/DynamicFindBy: Use find_by instead of dynamic find_by_token_for.
    @user = User.find_by_token_for(:confirm_email_token, params[:confirmation_token])

Steps to reproduce the problem

RuboCop version

$ bundle exec rubocop -V
1.36.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.1.2) [x86_64-linux]
  - rubocop-rails 2.16.1

Thanks :)

koic added a commit to koic/rubocop-rails that referenced this issue Sep 20, 2022
Fixes rubocop#781.

This PR fixes a false positive for `Rails/DynamicFindBy`
when using `find_by_token_for`.
This default setting emphasizes suppressing false positive
over false negative.
`find_by_token_for` is probably rarely named, but it will
always exist in Rails in the future.
koic added a commit to koic/rubocop-rails that referenced this issue Sep 20, 2022
Fixes rubocop#781.

This PR makes `Rails/DynamicFindBy` aware of `find_by_token_for`.
This default setting emphasizes suppressing false positive
over false negative.
`find_by_token_for` is probably rarely named, but it will
always exist in Rails in the future.
koic added a commit to koic/rubocop-rails that referenced this issue Sep 26, 2022
Fixes rubocop#781.

This PR makes `Rails/DynamicFindBy` aware of `find_by_token_for`.
This default setting emphasizes suppressing false positive
over false negative.
`find_by_token_for` is probably rarely named, but it will
always exist in Rails in the future.
@koic koic closed this as completed in #783 Sep 28, 2022
koic added a commit that referenced this issue Sep 28, 2022
…mic_find_by

[Fix #781] Fix a false positive for `Rails/DynamicFindBy`
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 a pull request may close this issue.

1 participant