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
This commit is contained in:
Claire
2023-04-09 11:25:30 +02:00
committed by GitHub
parent 29a91b871e
commit ff168ef202
45 changed files with 211 additions and 216 deletions

View File

@ -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) }
if duplicates.length == non_migrated.length || non_migrated.length == 0
# 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 = 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

View File

@ -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