From a5def0cdb537b4593c920a04ae3e8bcfe42d09e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 26 Oct 2019 00:07:30 +0200 Subject: [PATCH] Apply Style/AndOr and Style/Not rubocop rules The `and` and `or` keywords are not equivalent to `&&` and `||` and its use is counterintuitive. Here's an example ``` good = true && false # good if false bad = true and false # bad is true ``` The reason is `and` and `or` are control flow operators. So the code: ``` bad = true and false ``` Is equivalent to: ``` if bad = true false end ``` --- .rubocop.yml | 6 ++++++ config/initializers/devise_security_extension.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index c63b76e90..8b87da99b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -367,9 +367,15 @@ Security/JSONLoad: Security/YAMLLoad: Enabled: true +Style/AndOr: + Enabled: true + Style/BlockDelimiters: Enabled: true +Style/Not: + Enabled: true + Style/PercentLiteralDelimiters: Enabled: true diff --git a/config/initializers/devise_security_extension.rb b/config/initializers/devise_security_extension.rb index 51cf56429..8a86bb15d 100644 --- a/config/initializers/devise_security_extension.rb +++ b/config/initializers/devise_security_extension.rb @@ -62,7 +62,7 @@ module Devise if !self.new_record? && !self.encrypted_password_change.nil? && !self.erased? dummy = self.class.new dummy.encrypted_password = self.encrypted_password_change.first - dummy.password_salt = self.password_salt_change.first if self.respond_to? :password_salt_change and not self.password_salt_change.nil? + dummy.password_salt = self.password_salt_change.first if self.respond_to?(:password_salt_change) && !self.password_salt_change.nil? self.errors.add(:password, :equal_to_current_password) if dummy.valid_password?(self.password) end end