mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-30 18:47:51 +00:00
* fix: downcase email when finding * feat: add `from_email` class * refactor: use `from_email` * feat: add rule to disallow find_by email directly * chore: remove redundant test Since the previous imlpmentation didn't do a case-insentive search, a new user would be created, and the error would be raised at the DB layer. With the new changes, this test case is redundant * refactor: use from_email
17 lines
413 B
Ruby
17 lines
413 B
Ruby
require 'rubocop'
|
|
|
|
# Enforces use of from_email for email attribute lookups
|
|
class UseFromEmail < RuboCop::Cop::Cop
|
|
MSG = 'Use `from_email` for email lookups to ensure case insensitivity.'.freeze
|
|
|
|
def_node_matcher :find_by_email?, <<~PATTERN
|
|
(send _ :find_by (hash (pair (sym :email) _)))
|
|
PATTERN
|
|
|
|
def on_send(node)
|
|
return unless find_by_email?(node)
|
|
|
|
add_offense(node, message: MSG)
|
|
end
|
|
end
|