浏览代码

Proc style, redundant returns

Maarten van den Berg 6 年之前
父节点
当前提交
14aef99d0e

+ 0 - 20
.rubocop.yml

@@ -246,15 +246,6 @@ Style/RedundantParentheses:
246 246
   Exclude:
247 247
     - 'db/seeds.rb'
248 248
 
249
-# Offense count: 5
250
-# Cop supports --auto-correct.
251
-# Configuration parameters: AllowMultipleReturnValues.
252
-Style/RedundantReturn:
253
-  Exclude:
254
-    - 'app/helpers/authentication_helper.rb'
255
-    - 'app/models/activity.rb'
256
-    - 'app/models/person.rb'
257
-
258 249
 # Offense count: 85
259 250
 # Cop supports --auto-correct.
260 251
 Style/RedundantSelf:
@@ -282,17 +273,6 @@ Style/StringLiterals:
282 273
 Style/SymbolArray:
283 274
   EnforcedStyle: brackets
284 275
 
285
-# Offense count: 5
286
-# Cop supports --auto-correct.
287
-# Configuration parameters: IgnoredMethods.
288
-# IgnoredMethods: respond_to, define_method
289
-Style/SymbolProc:
290
-  Exclude:
291
-    - 'app/controllers/activities_controller.rb'
292
-    - 'app/models/activity.rb'
293
-    - 'app/models/member.rb'
294
-    - 'db/migrate/20180904163645_generate_calendar_tokens.rb'
295
-
296 276
 # Offense count: 3
297 277
 # Cop supports --auto-correct.
298 278
 # Configuration parameters: WordRegex.

+ 1 - 3
app/controllers/activities_controller.rb

@@ -298,9 +298,7 @@ class ActivitiesController < ApplicationController
298 298
     uploaded_io = params[:spreadsheet]
299 299
     result = Activity.from_csv(uploaded_io.read, @group)
300 300
 
301
-    result.each do |a|
302
-      a.save!
303
-    end
301
+    result.each(&:save!)
304 302
 
305 303
     flash_message(:success, I18n.t('activities.mass_imported', count: result.count))
306 304
     redirect_to group_activities_path(@group)

+ 3 - 3
app/helpers/authentication_helper.rb

@@ -64,7 +64,7 @@ module AuthenticationHelper
64 64
 
65 65
       return false if !@user_session.active || @user_session.expires < Time.now
66 66
 
67
-      return true
67
+      true
68 68
 
69 69
     else
70 70
       # Case 2: User is returning and has a remember token saved.
@@ -89,7 +89,7 @@ module AuthenticationHelper
89 89
         return false
90 90
       end
91 91
 
92
-      return false
92
+      false
93 93
     end
94 94
   end
95 95
 
@@ -127,7 +127,7 @@ module AuthenticationHelper
127 127
     Raven.user_context(
128 128
       user_firstname: current_person.first_name
129 129
     )
130
-    return true
130
+    true
131 131
   end
132 132
 
133 133
   def require_admin!

+ 3 - 5
app/models/activity.rb

@@ -122,7 +122,7 @@ class Activity < ApplicationRecord
122 122
     p = c[true]
123 123
     a = c[false]
124 124
     u = c[nil]
125
-    return "#{p || 0}, #{a || 0}, #{u || 0}"
125
+    "#{p || 0}, #{a || 0}, #{u || 0}"
126 126
   end
127 127
 
128 128
   # Determine whether the passed Person may change this activity.
@@ -220,7 +220,7 @@ class Activity < ApplicationRecord
220 220
     return if self.reminder_at > Time.zone.now
221 221
 
222 222
     participants = self.participants.where(attending: nil)
223
-    participants.each { |p| p.send_reminder }
223
+    participants.each(&:send_reminder)
224 224
 
225 225
     self.reminder_done = true
226 226
     self.save
@@ -302,9 +302,7 @@ class Activity < ApplicationRecord
302 302
          .joins(:person)
303 303
          .where.not(subgroup: nil)
304 304
 
305
-    ps.each do |pp|
306
-      pp.send_subgroup_notification
307
-    end
305
+    ps.each(&:send_subgroup_notification)
308 306
   end
309 307
 
310 308
   private

+ 1 - 3
app/models/member.rb

@@ -44,8 +44,6 @@ class Member < ApplicationRecord
44 44
       activity: self.group.future_activities
45 45
     )
46 46
 
47
-    participants.each do |p|
48
-      p.destroy!
49
-    end
47
+    participants.each(&:destroy!)
50 48
   end
51 49
 end

+ 1 - 1
app/models/person.rb

@@ -94,7 +94,7 @@ class Person < ApplicationRecord
94 94
       result << p
95 95
     end
96 96
 
97
-    return result
97
+    result
98 98
   end
99 99
 
100 100
   # @return [String]

+ 1 - 3
db/migrate/20180904163645_generate_calendar_tokens.rb

@@ -1,8 +1,6 @@
1 1
 class GenerateCalendarTokens < ActiveRecord::Migration[5.0]
2 2
   def up
3
-    Person.all.each do |p|
4
-      p.regenerate_calendar_token
5
-    end
3
+    Person.all.each(&:regenerate_calendar_token)
6 4
   end
7 5
 
8 6
   def down; end