Skip to content

Commit

Permalink
Fix Rails/CompactBlank cop (mastodon#24690)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Apr 30, 2023
1 parent d00e45a commit d902a70
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 18 deletions.
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def body_classes
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
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/statuses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def poll_summary(status)
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/attachmentable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def set_file_content_type(attachment) # rubocop:disable Naming/AccessorMethodNam
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)
Expand Down
2 changes: 1 addition & 1 deletion app/models/poll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def prepare_votes_count
end

def prepare_options
self.options = options.map(&:strip).reject(&:blank?)
self.options = options.map(&:strip).compact_blank
end

def reset_parent_cache
Expand Down
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ def sanitize_languages
return if chosen_languages.nil?

chosen_languages.compact_blank!

self.chosen_languages = nil if chosen_languages.empty?
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/import_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def import_bookmarks!
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
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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

Expand Down

0 comments on commit d902a70

Please sign in to comment.