Skip to content

Commit 6e6e072

Browse files
authored
Merge pull request rubocop#783 from koic/fix_a_false_positive_for_rails_dynamic_find_by
[Fix rubocop#781] Fix a false positive for `Rails/DynamicFindBy`
2 parents a94f456 + c4b25ae commit 6e6e072

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)