From d902a707a31686947b13c75e8152ab75328fd41e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Sun, 30 Apr 2023 08:07:21 -0400 Subject: [PATCH] Fix Rails/CompactBlank cop (#24690) --- .rubocop_todo.yml | 10 ---------- app/helpers/application_helper.rb | 2 +- app/helpers/statuses_helper.rb | 4 ++-- app/models/concerns/attachmentable.rb | 2 +- app/models/poll.rb | 2 +- app/models/user.rb | 1 - app/services/import_service.rb | 2 +- config/initializers/paperclip.rb | 2 +- 8 files changed, 7 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 171a11a0a1..d5770dc569 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1203,16 +1203,6 @@ Rails/BulkChangeTable: - 'db/migrate/20220303000827_add_ordered_media_attachment_ids_to_status_edits.rb' - 'db/migrate/20220824164433_add_human_identifier_to_admin_action_logs.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Rails/CompactBlank: - Exclude: - - 'app/helpers/application_helper.rb' - - 'app/helpers/statuses_helper.rb' - - 'app/models/concerns/attachmentable.rb' - - 'app/models/poll.rb' - - 'app/services/import_service.rb' - - 'config/initializers/paperclip.rb' - # Configuration parameters: Include. # Include: db/migrate/*.rb Rails/CreateTableWithTimestamps: diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8de89a181c..e2963328a2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -161,7 +161,7 @@ module ApplicationHelper output << 'system-font' if current_account&.user&.setting_system_font_ui output << (current_account&.user&.setting_reduce_motion ? 'reduce-motion' : 'no-reduce-motion') output << 'rtl' if locale_direction == 'rtl' - output.reject(&:blank?).join(' ') + output.compact_blank.join(' ') end def cdn_host diff --git a/app/helpers/statuses_helper.rb b/app/helpers/statuses_helper.rb index 9f87593674..f1f1ea872e 100644 --- a/app/helpers/statuses_helper.rb +++ b/app/helpers/statuses_helper.rb @@ -51,14 +51,14 @@ module StatusesHelper end def status_description(status) - components = [[media_summary(status), status_text_summary(status)].reject(&:blank?).join(' · ')] + components = [[media_summary(status), status_text_summary(status)].compact_blank.join(' · ')] if status.spoiler_text.blank? components << status.text components << poll_summary(status) end - components.reject(&:blank?).join("\n\n") + components.compact_blank.join("\n\n") end def stream_link_target diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index d44c224381..9cafedc209 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -46,7 +46,7 @@ module Attachmentable def set_file_extension(attachment) # rubocop:disable Naming/AccessorMethodName return if attachment.blank? - attachment.instance_write :file_name, [Paperclip::Interpolations.basename(attachment, :original), appropriate_extension(attachment)].delete_if(&:blank?).join('.') + attachment.instance_write :file_name, [Paperclip::Interpolations.basename(attachment, :original), appropriate_extension(attachment)].compact_blank!.join('.') end def check_image_dimension(attachment) diff --git a/app/models/poll.rb b/app/models/poll.rb index dd35e953b8..74a77978b9 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -101,7 +101,7 @@ class Poll < ApplicationRecord end def prepare_options - self.options = options.map(&:strip).reject(&:blank?) + self.options = options.map(&:strip).compact_blank end def reset_parent_cache diff --git a/app/models/user.rb b/app/models/user.rb index 9b225d75f1..b903344be9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -445,7 +445,6 @@ class User < ApplicationRecord return if chosen_languages.nil? chosen_languages.compact_blank! - self.chosen_languages = nil if chosen_languages.empty? end diff --git a/app/services/import_service.rb b/app/services/import_service.rb index 56f191c1fe..f6c94cbb6f 100644 --- a/app/services/import_service.rb +++ b/app/services/import_service.rb @@ -132,7 +132,7 @@ class ImportService < BaseService def parse_import_data!(default_headers) data = CSV.parse(import_data, headers: true) data = CSV.parse(import_data, headers: default_headers) unless data.headers&.first&.strip&.include?(' ') - @data = data.reject(&:blank?) + @data = data.compact_blank end def import_data diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index bd37f67093..b72cbe1927 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -7,7 +7,7 @@ Paperclip.interpolates :filename do |attachment, style| if style == :original attachment.original_filename else - [basename(attachment, style), extension(attachment, style)].delete_if(&:blank?).join('.') + [basename(attachment, style), extension(attachment, style)].compact_blank!.join('.') end end