Browse Source

Fix low-hanging rubocop gripes (#8458)

* rubocop: quit being so picky

* rubocop: miscellany

* rubocop: prefer present to blank
Quint Guvernator 1 month ago
parent
commit
da13fa5021

+ 6
- 0
.rubocop.yml View File

@@ -62,6 +62,9 @@ Metrics/ParameterLists:
62 62
 Metrics/PerceivedComplexity:
63 63
   Max: 20
64 64
 
65
+Naming/MemoizedInstanceVariableName:
66
+  Enabled: false
67
+
65 68
 Rails:
66 69
   Enabled: true
67 70
 
@@ -71,6 +74,9 @@ Rails/HasAndBelongsToMany:
71 74
 Rails/SkipsModelValidations:
72 75
   Enabled: false
73 76
 
77
+Rails/HttpStatus:
78
+  Enabled: false
79
+
74 80
 Style/ClassAndModuleChildren:
75 81
   Enabled: false
76 82
 

+ 1
- 1
app/controllers/api/v1/lists/accounts_controller.rb View File

@@ -1,7 +1,7 @@
1 1
 # frozen_string_literal: true
2 2
 
3 3
 class Api::V1::Lists::AccountsController < Api::BaseController
4
-  before_action -> { doorkeeper_authorize! :read, :'read:lists' },    only:  [:show]
4
+  before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:show]
5 5
   before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:show]
6 6
 
7 7
   before_action :require_user!

+ 1
- 1
app/controllers/api/v1/lists_controller.rb View File

@@ -1,7 +1,7 @@
1 1
 # frozen_string_literal: true
2 2
 
3 3
 class Api::V1::ListsController < Api::BaseController
4
-  before_action -> { doorkeeper_authorize! :read, :'read:lists' },    only:  [:index, :show]
4
+  before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:index, :show]
5 5
   before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:index, :show]
6 6
 
7 7
   before_action :require_user!

+ 1
- 1
app/lib/feed_manager.rb View File

@@ -288,7 +288,7 @@ class FeedManager
288 288
       # remains in the set. We could pick a random element, but this
289 289
       # set should generally be small, and it seems ideal to show the
290 290
       # oldest potential such reblog.
291
-      other_reblog = redis.smembers(reblog_set_key).map(&:to_i).sort.first
291
+      other_reblog = redis.smembers(reblog_set_key).map(&:to_i).min
292 292
 
293 293
       redis.zadd(timeline_key, other_reblog, other_reblog) if other_reblog
294 294
 

+ 1
- 1
app/mailers/user_mailer.rb View File

@@ -16,7 +16,7 @@ class UserMailer < Devise::Mailer
16 16
     return if @resource.disabled?
17 17
 
18 18
     I18n.with_locale(@resource.locale || I18n.default_locale) do
19
-      mail to: @resource.unconfirmed_email.blank? ? @resource.email : @resource.unconfirmed_email,
19
+      mail to: @resource.unconfirmed_email.presence || @resource.email,
20 20
            subject: I18n.t(@resource.pending_reconfirmation? ? 'devise.mailer.reconfirmation_instructions.subject' : 'devise.mailer.confirmation_instructions.subject', instance: @instance),
21 21
            template_name: @resource.pending_reconfirmation? ? 'reconfirmation_instructions' : 'confirmation_instructions'
22 22
     end

+ 1
- 1
app/models/concerns/expireable.rb View File

@@ -9,7 +9,7 @@ module Expireable
9 9
     attr_reader :expires_in
10 10
 
11 11
     def expires_in=(interval)
12
-      self.expires_at = interval.to_i.seconds.from_now unless interval.blank?
12
+      self.expires_at = interval.to_i.seconds.from_now if interval.present?
13 13
       @expires_in     = interval
14 14
     end
15 15
 

+ 2
- 2
app/models/user.rb View File

@@ -98,7 +98,7 @@ class User < ApplicationRecord
98 98
            :reduce_motion, :system_font_ui, :noindex, :theme, :display_sensitive_media, :hide_network,
99 99
            :default_language, to: :settings, prefix: :setting, allow_nil: false
100 100
 
101
-  attr_accessor :invite_code
101
+  attr_reader :invite_code
102 102
 
103 103
   def pam_conflict(_)
104 104
     # block pam login tries on traditional account
@@ -258,7 +258,7 @@ class User < ApplicationRecord
258 258
   end
259 259
 
260 260
   def invite_code=(code)
261
-    self.invite  = Invite.find_by(code: code) unless code.blank?
261
+    self.invite  = Invite.find_by(code: code) if code.present?
262 262
     @invite_code = code
263 263
   end
264 264
 

+ 1
- 1
lib/tasks/db.rake View File

@@ -18,7 +18,7 @@ def each_schema_load_environment
18 18
   #    needing to do the same, and we can't even use the same method
19 19
   #    to do it.
20 20
 
21
-  if Rails.env == 'development'
21
+  if Rails.env.development?
22 22
     test_conf = ActiveRecord::Base.configurations['test']
23 23
 
24 24
     if test_conf['database']&.present?

+ 12
- 16
lib/tasks/mastodon.rake View File

@@ -280,14 +280,14 @@ namespace :mastodon do
280 280
 
281 281
         begin
282 282
           ActionMailer::Base.smtp_settings = {
283
-            :port                 => env['SMTP_PORT'],
284
-            :address              => env['SMTP_SERVER'],
285
-            :user_name            => env['SMTP_LOGIN'].presence,
286
-            :password             => env['SMTP_PASSWORD'].presence,
287
-            :domain               => env['LOCAL_DOMAIN'],
288
-            :authentication       => env['SMTP_AUTH_METHOD'] == 'none' ? nil : env['SMTP_AUTH_METHOD'] || :plain,
289
-            :openssl_verify_mode  => env['SMTP_OPENSSL_VERIFY_MODE'],
290
-            :enable_starttls_auto => true,
283
+            port:                 env['SMTP_PORT'],
284
+            address:              env['SMTP_SERVER'],
285
+            user_name:            env['SMTP_LOGIN'].presence,
286
+            password:             env['SMTP_PASSWORD'].presence,
287
+            domain:               env['LOCAL_DOMAIN'],
288
+            authentication:       env['SMTP_AUTH_METHOD'] == 'none' ? nil : env['SMTP_AUTH_METHOD'] || :plain,
289
+            openssl_verify_mode:  env['SMTP_OPENSSL_VERIFY_MODE'],
290
+            enable_starttls_auto: true,
291 291
           }
292 292
 
293 293
           ActionMailer::Base.default_options = {
@@ -326,13 +326,11 @@ namespace :mastodon do
326 326
 
327 327
         if prompt.yes?('Prepare the database now?')
328 328
           prompt.say 'Running `RAILS_ENV=production rails db:setup` ...'
329
-          prompt.say "\n"
329
+          prompt.say "\n\n"
330 330
 
331 331
           if cmd.run!({ RAILS_ENV: 'production', SAFETY_ASSURED: 1 }, :rails, 'db:setup').failure?
332
-            prompt.say "\n"
333 332
             prompt.error 'That failed! Perhaps your configuration is not right'
334 333
           else
335
-            prompt.say "\n"
336 334
             prompt.ok 'Done!'
337 335
           end
338 336
         end
@@ -343,13 +341,11 @@ namespace :mastodon do
343 341
 
344 342
         if prompt.yes?('Compile the assets now?')
345 343
           prompt.say 'Running `RAILS_ENV=production rails assets:precompile` ...'
346
-          prompt.say "\n"
344
+          prompt.say "\n\n"
347 345
 
348 346
           if cmd.run!({ RAILS_ENV: 'production' }, :rails, 'assets:precompile').failure?
349
-            prompt.say "\n"
350 347
             prompt.error 'That failed! Maybe you need swap space?'
351 348
           else
352
-            prompt.say "\n"
353 349
             prompt.say 'Done!'
354 350
           end
355 351
         end
@@ -715,10 +711,10 @@ namespace :mastodon do
715 711
       pastel = Pastel.new
716 712
 
717 713
       duplicate_masters.each do |account|
718
-        puts pastel.yellow("First of their name: ") + pastel.bold(account.username) + " (#{admin_account_url(account.id)})"
714
+        puts pastel.yellow('First of their name: ') + pastel.bold(account.username) + " (#{admin_account_url(account.id)})"
719 715
 
720 716
         Account.where('lower(username) = ?', account.username.downcase).where.not(id: account.id).each do |duplicate|
721
-          puts "  " + pastel.red("Duplicate: ") + admin_account_url(duplicate.id)
717
+          puts '  ' + pastel.red('Duplicate: ') + admin_account_url(duplicate.id)
722 718
         end
723 719
       end
724 720
     end