Browse Source

Negated if, Not

Maarten van den Berg 6 years ago
parent
commit
9afdf65599

+ 0 - 28
.rubocop.yml

@@ -221,23 +221,6 @@ Style/MutableConstant:
221 221
     - 'app/models/participant.rb'
222 222
     - 'app/models/token.rb'
223 223
 
224
-# Offense count: 18
225
-# Cop supports --auto-correct.
226
-# Configuration parameters: EnforcedStyle.
227
-# SupportedStyles: both, prefix, postfix
228
-Style/NegatedIf:
229
-  Exclude:
230
-    - 'app/controllers/activities_controller.rb'
231
-    - 'app/controllers/authentication_controller.rb'
232
-    - 'app/controllers/dashboard_controller.rb'
233
-    - 'app/controllers/members_controller.rb'
234
-    - 'app/helpers/activities_helper.rb'
235
-    - 'app/helpers/authentication_helper.rb'
236
-    - 'app/helpers/groups_helper.rb'
237
-    - 'app/models/activity.rb'
238
-    - 'app/models/member.rb'
239
-    - 'app/models/person.rb'
240
-
241 224
 # Offense count: 1
242 225
 # Cop supports --auto-correct.
243 226
 # Configuration parameters: EnforcedStyle, MinBodyLength.
@@ -246,17 +229,6 @@ Style/Next:
246 229
   Exclude:
247 230
     - 'db/seeds.rb'
248 231
 
249
-# Offense count: 12
250
-# Cop supports --auto-correct.
251
-Style/Not:
252
-  Exclude:
253
-    - 'app/controllers/authentication_controller.rb'
254
-    - 'app/controllers/members_controller.rb'
255
-    - 'app/helpers/authentication_helper.rb'
256
-    - 'app/models/activity.rb'
257
-    - 'app/models/member.rb'
258
-    - 'app/models/person.rb'
259
-
260 232
 # Offense count: 1
261 233
 # Cop supports --auto-correct.
262 234
 # Configuration parameters: Strict.

+ 1 - 1
app/controllers/activities_controller.rb

@@ -161,7 +161,7 @@ class ActivitiesController < ApplicationController
161 161
     @non_organizers_options.sort!
162 162
     @organizers_options.sort!
163 163
 
164
-    @subgroup = Subgroup.new if !@subgroup
164
+    @subgroup ||= Subgroup.new
165 165
     @subgroups = @activity.subgroups.order(is_assignable: :desc, name: :asc)
166 166
   end
167 167
 

+ 5 - 5
app/controllers/authentication_controller.rb

@@ -16,7 +16,7 @@ class AuthenticationController < ApplicationController
16 16
 
17 17
         flash_message(:success, I18n.t(:greeting, name: u.person.first_name))
18 18
         redirect_to root_path
19
-      elsif u && (not u.confirmed)
19
+      elsif u && !u.confirmed
20 20
         flash_message(:warning, I18n.t('authentication.activation_required'))
21 21
         redirect_to action: 'login_form'
22 22
       else
@@ -46,7 +46,7 @@ class AuthenticationController < ApplicationController
46 46
   def create_password
47 47
     person = Person.find_by(email: params[:user][:email])
48 48
 
49
-    if not person
49
+    unless person
50 50
       flash_message(:warning, I18n.t('authentication.unknown_email'))
51 51
       redirect_to action: 'create_password_form'
52 52
       return
@@ -59,7 +59,7 @@ class AuthenticationController < ApplicationController
59 59
       return
60 60
     end
61 61
 
62
-    if not user
62
+    unless user
63 63
       user = User.new
64 64
       user.person = person
65 65
       user.email = person.email
@@ -79,7 +79,7 @@ class AuthenticationController < ApplicationController
79 79
 
80 80
   def forgotten_password
81 81
     user = User.find_by(email: params[:password_reset][:email])
82
-    if not user
82
+    unless user
83 83
       flash_message(:danger, I18n.t('authentication.unknown_email'))
84 84
       redirect_to action: 'forgotten_password_form'
85 85
       return
@@ -91,7 +91,7 @@ class AuthenticationController < ApplicationController
91 91
 
92 92
   def reset_password_form
93 93
     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
94
-    if not token_valid? token
94
+    unless token_valid? token
95 95
       return
96 96
     end
97 97
 

+ 1 - 1
app/controllers/dashboard_controller.rb

@@ -52,7 +52,7 @@ class DashboardController < ApplicationController
52 52
     new = params[:new_password]
53 53
     confirm = params[:new_password_confirm]
54 54
 
55
-    if !u.authenticate(current)
55
+    unless u.authenticate(current)
56 56
       flash_message(:danger, t('authentication.invalid_pass'))
57 57
       redirect_to settings_path
58 58
       return

+ 2 - 2
app/controllers/members_controller.rb

@@ -42,11 +42,11 @@ class MembersController < ApplicationController
42 42
   def process_invite
43 43
     @person = Person.find_by(email: params[:person][:email])
44 44
     new_rec = false
45
-    if not @person
45
+    unless @person
46 46
       @person = Person.new(invite_params)
47 47
       new_rec = true
48 48
 
49
-      if not @person.save
49
+      unless @person.save
50 50
         respond_to do |format|
51 51
           format.html { render 'invite' }
52 52
           format.json { render json: @person.errors, status: :unprocessable_entity }

+ 1 - 1
app/helpers/activities_helper.rb

@@ -1,6 +1,6 @@
1 1
 module ActivitiesHelper
2 2
   def require_organizer!
3
-    if !@activity.may_change?(current_person)
3
+    unless @activity.may_change?(current_person)
4 4
       flash_message(:danger, I18n.t('authentication.organizer_required'))
5 5
       redirect_to group_activity_path(@group, @activity)
6 6
     end

+ 3 - 3
app/helpers/authentication_helper.rb

@@ -103,7 +103,7 @@ module AuthenticationHelper
103 103
     end
104 104
 
105 105
     # Edge case if a session no longer exists in the database
106
-    if not @user_session
106
+    unless @user_session
107 107
       log_out(session_broken: true)
108 108
     end
109 109
   end
@@ -118,7 +118,7 @@ module AuthenticationHelper
118 118
   end
119 119
 
120 120
   def require_login!
121
-    if !is_logged_in?
121
+    unless is_logged_in?
122 122
       flash_message(:warning, I18n.t('authentication.login_required'))
123 123
       redirect_to controller: 'authentication', action: 'login_form'
124 124
       return false
@@ -131,7 +131,7 @@ module AuthenticationHelper
131 131
   end
132 132
 
133 133
   def require_admin!
134
-    if !current_person.is_admin?
134
+    unless current_person.is_admin?
135 135
       flash_message(:danger, I18n.t('authentication.admin_required'))
136 136
       redirect_to '/dashboard'
137 137
     end

+ 3 - 3
app/helpers/groups_helper.rb

@@ -2,7 +2,7 @@ module GroupsHelper
2 2
   def require_membership!
3 3
     return unless require_login!
4 4
 
5
-    if !(@group.is_member?(current_person) || current_person.is_admin?)
5
+    unless @group.is_member?(current_person) || current_person.is_admin?
6 6
       flash_message(:danger, I18n.t('groups.membership_required'))
7 7
       redirect_to dashboard_home_path
8 8
     end
@@ -11,8 +11,8 @@ module GroupsHelper
11 11
   def require_leader!
12 12
     return unless require_login!
13 13
 
14
-    if !(@group.is_leader?(current_person) ||
15
-         current_person.is_admin?)
14
+    unless @group.is_leader?(current_person) ||
15
+           current_person.is_admin?
16 16
       flash_message(:danger, I18n.t('groups.leadership_required'))
17 17
       redirect_to dashboard_home_path
18 18
     end

+ 1 - 1
app/models/activity.rb

@@ -137,7 +137,7 @@ class Activity < ApplicationRecord
137 137
   #  2. do not have Participants (and thus, no way to confirm) yet
138 138
   def create_missing_participants!
139 139
     people = self.group.people
140
-    if not self.participants.empty?
140
+    unless self.participants.empty?
141 141
       people = people.where('people.id NOT IN (?)', self.people.ids)
142 142
     end
143 143
 

+ 1 - 1
app/models/member.rb

@@ -22,7 +22,7 @@ class Member < ApplicationRecord
22 22
   def create_future_participants!
23 23
     activities = self.group.future_activities
24 24
 
25
-    if not self.person.activities.empty?
25
+    unless self.person.activities.empty?
26 26
       activities = activities.where(
27 27
         'activities.id NOT IN (?)', self.person.activities.ids
28 28
       )

+ 2 - 2
app/models/person.rb

@@ -82,7 +82,7 @@ class Person < ApplicationRecord
82 82
     result = []
83 83
     reader.each do |row|
84 84
       p = Person.find_by(email: row['email'])
85
-      if not p
85
+      unless p
86 86
         p = Person.new
87 87
         p.first_name  = row['first_name']
88 88
         p.infix       = row['infix']
@@ -207,7 +207,7 @@ class Person < ApplicationRecord
207 207
   # Ensure the person's user email is updated at the same time as the person's
208 208
   # email.
209 209
   def update_user_email
210
-    if not self.user.nil?
210
+    unless self.user.nil?
211 211
       self.user.update!(email: self.email)
212 212
     end
213 213
   end