Add and apply Rails/FindByOrAssignmentMemoization rule
This rule was added in rubocop-rails 2.33. At first, I wasn't very fond of this rule. It made the code less readable even if it improved performace in some cases. Then I realized that in the `Admin::MachineLearning::SettingComponent` we were using `find_by` when we should be using `find_by!` instead, and we detected that thanks to this rule. So, only for that reason, I'm adding this rule, but I'm fine if we remove it.
This commit is contained in:
@@ -441,6 +441,9 @@ Rails/FindBy:
|
||||
Exclude:
|
||||
- "config/initializers/ahoy.rb"
|
||||
|
||||
Rails/FindByOrAssignmentMemoization:
|
||||
Enabled: true
|
||||
|
||||
Rails/FindEach:
|
||||
Enabled: true
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class Admin::MachineLearning::SettingComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def setting
|
||||
@setting ||= Setting.find_by(key: "machine_learning.#{kind}")
|
||||
@setting ||= Setting.find_by!(key: "machine_learning.#{kind}")
|
||||
end
|
||||
|
||||
def ml_info
|
||||
|
||||
@@ -27,7 +27,9 @@ class Dashboard::SuccessfulSupportsController < Dashboard::BaseController
|
||||
end
|
||||
|
||||
def successful_proposal
|
||||
@successful_proposal ||= Proposal.find_by(id: Setting["proposals.successful_proposal_id"])
|
||||
return @successful_proposal if defined?(@successful_proposal)
|
||||
|
||||
@successful_proposal = Proposal.find_by(id: Setting["proposals.successful_proposal_id"])
|
||||
end
|
||||
|
||||
def days_diff
|
||||
|
||||
@@ -11,7 +11,9 @@ class Verification::Management::Email
|
||||
delegate :username, to: :user, allow_nil: true
|
||||
|
||||
def user
|
||||
@user ||= User.find_by(email: email)
|
||||
return @user if defined?(@user)
|
||||
|
||||
@user = User.find_by(email: email)
|
||||
end
|
||||
|
||||
def user?
|
||||
|
||||
Reference in New Issue
Block a user