about summary refs log tree commit diff
path: root/config/initializers
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-04-09 11:25:30 +0200
committerGitHub <noreply@github.com>2023-04-09 11:25:30 +0200
commitff168ef2024626f37fa776fde5739dcd58ecb9f2 (patch)
tree5b638b2e5a43445a75133a9b510bff00d44ea986 /config/initializers
parent29a91b871eb4fb375baa3701e29cfb35f884bb98 (diff)
Fix most rubocop issues (#2165)
* Run rubocop --autocorrect on app/, config/ and lib/, also manually fix some remaining style issues

* Run rubocop --autocorrect-all on db/

* Run rubocop --autocorrect-all on `spec/` and fix remaining issues
Diffstat (limited to 'config/initializers')
-rw-r--r--config/initializers/0_duplicate_migrations.rb24
-rw-r--r--config/initializers/simple_form.rb1
2 files changed, 15 insertions, 10 deletions
diff --git a/config/initializers/0_duplicate_migrations.rb b/config/initializers/0_duplicate_migrations.rb
index 6c45e4bd2..1b8b59025 100644
--- a/config/initializers/0_duplicate_migrations.rb
+++ b/config/initializers/0_duplicate_migrations.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Some migrations have been present in glitch-soc for a long time and have then
 # been merged in upstream Mastodon, under a different version number.
 #
@@ -12,24 +14,26 @@
 # we decided monkey-patching Rails' Migrator to completely ignore the duplicate,
 # keeping only the one that has run, or an arbitrary one.
 
-ALLOWED_DUPLICATES = [20180410220657, 20180831171112].freeze
+ALLOWED_DUPLICATES = [2018_04_10_220657, 2018_08_31_171112].freeze
 
 module ActiveRecord
   class Migrator
     def self.new(direction, migrations, schema_migration, target_version = nil)
       migrated = Set.new(Base.connection.migration_context.get_all_versions)
 
-      migrations.group_by(&:name).each do |name, duplicates|
-        if duplicates.length > 1 && duplicates.all? { |m| ALLOWED_DUPLICATES.include?(m.version) }
-          # We have a set of allowed duplicates. Keep the migrated one, if any.
-          non_migrated = duplicates.reject { |m| migrated.include?(m.version.to_i) }
+      migrations.group_by(&:name).each do |_name, duplicates|
+        next unless duplicates.length > 1 && duplicates.all? { |m| ALLOWED_DUPLICATES.include?(m.version) }
+
+        # We have a set of allowed duplicates. Keep the migrated one, if any.
+        non_migrated = duplicates.reject { |m| migrated.include?(m.version.to_i) }
 
-          if duplicates.length == non_migrated.length || non_migrated.length == 0
+        migrations = begin
+          if duplicates.length == non_migrated.length || non_migrated.empty?
             # There weren't any migrated one, so we have to pick one “canonical” migration
-            migrations = migrations - duplicates[1..-1]
+            migrations - duplicates[1..]
           else
             # Just reject every duplicate which hasn't been migrated yet
-            migrations = migrations - non_migrated
+            migrations - non_migrated
           end
         end
       end
@@ -43,10 +47,10 @@ module ActiveRecord
       # A set of duplicated migrations is considered migrated if at least one of
       # them is migrated.
       migrated = get_all_versions
-      migrations.group_by(&:name).each do |name, duplicates|
+      migrations.group_by(&:name).each do |_name, duplicates|
         return true unless duplicates.any? { |m| migrated.include?(m.version.to_i) }
       end
-      return false
+      false
     end
   end
 end
diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb
index d167a1600..fff4f538e 100644
--- a/config/initializers/simple_form.rb
+++ b/config/initializers/simple_form.rb
@@ -22,6 +22,7 @@ end
 module GlitchOnlyComponent
   def glitch_only(_wrapper_options = nil)
     return unless options[:glitch_only]
+
     options[:label_text] = ->(raw_label_text, _required_label_text, _label_present) { safe_join([raw_label_text, ' ', content_tag(:span, I18n.t('simple_form.glitch_only'), class: 'glitch_only')]) }
     nil
   end