Skip to content

Commit c4b25ae

Browse files
committed
[Fix rubocop#781] Fix a false positive for Rails/DynamicFindBy
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.
1 parent 313cd20 commit c4b25ae

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#781](https://github.com/rubocop/rubocop-rails/issues/781): Make `Rails/DynamicFindBy` aware of `find_by_token_for`. ([@koic][])

config/default.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,10 @@ Rails/DynamicFindBy:
348348
# The `Whitelist` has been deprecated, Please use `AllowedMethods` instead.
349349
Whitelist:
350350
- find_by_sql
351+
- find_by_token_for
351352
AllowedMethods:
352353
- find_by_sql
354+
- find_by_token_for
353355
AllowedReceivers:
354356
- Gem::Specification
355357

lib/rubocop/cop/rails/dynamic_find_by.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ module Rails
2222
# User.find_by(name: name, email: email)
2323
# User.find_by!(email: email)
2424
#
25-
# @example AllowedMethods: ['find_by_sql'] (default)
25+
# @example AllowedMethods: ['find_by_sql', 'find_by_token_for'] (default)
2626
# # bad
2727
# User.find_by_query(users_query)
28+
# User.find_by_token_for(:password_reset, token)
2829
#
2930
# # good
3031
# User.find_by_sql(users_sql)
32+
# User.find_by_token_for(:password_reset, token)
3133
#
3234
# @example AllowedReceivers: ['Gem::Specification'] (default)
3335
# # bad

0 commit comments

Comments
 (0)