Avoid assignments in conditions

This commit is contained in:
gregoirenovel 2018-03-06 12:01:45 +01:00
parent d3f0fc703a
commit 7489b8d1aa
3 changed files with 7 additions and 3 deletions

View file

@ -280,7 +280,7 @@ Lint/AmbiguousRegexpLiteral:
Enabled: true
Lint/AssignmentInCondition:
Enabled: false
Enabled: true
Lint/BigDecimalNew:
Enabled: true

View file

@ -78,7 +78,9 @@ class Users::SessionsController < Sessions::SessionsController
end
def try_to_authenticate(klass, remember_me = false)
if resource = klass.find_for_database_authentication(email: params[:user][:email])
resource = klass.find_for_database_authentication(email: params[:user][:email])
if resource.present?
if resource.valid_password?(params[:user][:password])
resource.remember_me = remember_me
sign_in resource

View file

@ -7,7 +7,9 @@ class FileSizeValidator < ActiveModel::EachValidator
RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long]
def initialize(options)
if range = (options.delete(:in) || options.delete(:within))
range = options.delete(:in) || options.delete(:within)
if range.present?
raise ArgumentError, ":in and :within must be a Range" if !range.is_a?(Range)
options[:minimum], options[:maximum] = range.begin, range.end
options[:maximum] -= 1 if range.exclude_end?