Skip to content

Commit

Permalink
Autofix Rubocop remaining Layout rules (mastodon#23679)
Browse files Browse the repository at this point in the history
  • Loading branch information
nschonni authored Feb 20, 2023
1 parent d2dcb6c commit 717683d
Show file tree
Hide file tree
Showing 117 changed files with 265 additions and 261 deletions.
148 changes: 0 additions & 148 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,154 +14,6 @@ Bundler/OrderedGems:
Exclude:
- 'Gemfile'

# Offense count: 81
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'app/controllers/api/v1/tags_controller.rb'
- 'app/controllers/application_controller.rb'
- 'app/controllers/concerns/session_tracking_concern.rb'
- 'app/controllers/concerns/signature_verification.rb'
- 'app/helpers/application_helper.rb'
- 'app/lib/activitypub/activity.rb'
- 'app/lib/activitypub/tag_manager.rb'
- 'app/lib/request.rb'
- 'app/lib/settings/scoped_settings.rb'
- 'app/lib/status_filter.rb'
- 'app/lib/tag_manager.rb'
- 'app/lib/webfinger.rb'
- 'app/models/account.rb'
- 'app/models/account_conversation.rb'
- 'app/models/admin/import.rb'
- 'app/models/custom_filter.rb'
- 'app/models/favourite.rb'
- 'app/models/form/admin_settings.rb'
- 'app/models/poll.rb'
- 'app/models/session_activation.rb'
- 'app/models/setting.rb'
- 'app/models/status_edit.rb'
- 'app/models/user.rb'
- 'app/models/user_role.rb'
- 'app/services/activitypub/fetch_remote_actor_service.rb'
- 'app/services/activitypub/fetch_remote_status_service.rb'
- 'app/services/activitypub/fetch_replies_service.rb'
- 'app/services/activitypub/process_account_service.rb'
- 'app/services/favourite_service.rb'
- 'app/services/notify_service.rb'
- 'app/services/post_status_service.rb'
- 'app/services/vote_service.rb'
- 'app/validators/follow_limit_validator.rb'
- 'app/validators/unreserved_username_validator.rb'
- 'app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb'
- 'db/migrate/20190314181829_migrate_open_registrations_setting.rb'
- 'db/migrate/20190529143559_preserve_old_layout_for_existing_users.rb'
- 'db/migrate/20210421121431_add_case_insensitive_btree_index_to_tags.rb'
- 'db/post_migrate/20221101190723_backfill_admin_action_logs.rb'
- 'db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb'
- 'lib/mastodon/domains_cli.rb'

# Offense count: 71
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterMagicComment:
Exclude:
- 'Capfile'
- 'app/helpers/languages_helper.rb'
- 'app/models/account.rb'
- 'app/models/account_conversation.rb'
- 'app/models/account_domain_block.rb'
- 'app/models/account_moderation_note.rb'
- 'app/models/account_note.rb'
- 'app/models/account_pin.rb'
- 'app/models/account_stat.rb'
- 'app/models/account_summary.rb'
- 'app/models/account_warning.rb'
- 'app/models/backup.rb'
- 'app/models/block.rb'
- 'app/models/bookmark.rb'
- 'app/models/canonical_email_block.rb'
- 'app/models/conversation.rb'
- 'app/models/conversation_mute.rb'
- 'app/models/custom_emoji.rb'
- 'app/models/custom_filter.rb'
- 'app/models/custom_filter_keyword.rb'
- 'app/models/custom_filter_status.rb'
- 'app/models/device.rb'
- 'app/models/domain_block.rb'
- 'app/models/email_domain_block.rb'
- 'app/models/encrypted_message.rb'
- 'app/models/favourite.rb'
- 'app/models/featured_tag.rb'
- 'app/models/follow.rb'
- 'app/models/follow_recommendation.rb'
- 'app/models/follow_recommendation_suppression.rb'
- 'app/models/follow_request.rb'
- 'app/models/identity.rb'
- 'app/models/import.rb'
- 'app/models/instance.rb'
- 'app/models/invite.rb'
- 'app/models/ip_block.rb'
- 'app/models/list.rb'
- 'app/models/list_account.rb'
- 'app/models/login_activity.rb'
- 'app/models/media_attachment.rb'
- 'app/models/mention.rb'
- 'app/models/mute.rb'
- 'app/models/notification.rb'
- 'app/models/one_time_key.rb'
- 'app/models/poll.rb'
- 'app/models/poll_vote.rb'
- 'app/models/preview_card.rb'
- 'app/models/preview_card_provider.rb'
- 'app/models/relay.rb'
- 'app/models/report.rb'
- 'app/models/report_note.rb'
- 'app/models/session_activation.rb'
- 'app/models/setting.rb'
- 'app/models/site_upload.rb'
- 'app/models/status.rb'
- 'app/models/status_edit.rb'
- 'app/models/status_pin.rb'
- 'app/models/status_stat.rb'
- 'app/models/tag.rb'
- 'app/models/unavailable_domain.rb'
- 'app/models/user.rb'
- 'app/models/user_ip.rb'
- 'app/models/web/push_subscription.rb'
- 'app/models/web/setting.rb'
- 'app/models/webauthn_credential.rb'
- 'config.ru'
- 'db/migrate/20220613110834_add_action_to_custom_filters.rb'
- 'db/post_migrate/20220613110802_remove_whole_word_from_custom_filters.rb'
- 'db/post_migrate/20220613110903_remove_irreversible_from_custom_filters.rb'
- 'spec/controllers/api/v1/accounts/statuses_controller_spec.rb'
- 'spec/models/tag_spec.rb'

# Offense count: 113
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/HashAlignment:
Exclude:
- 'app/lib/activitypub/linked_data_signature.rb'
- 'app/lib/ostatus/tag_manager.rb'
- 'app/models/account/field.rb'
- 'app/models/account_warning.rb'
- 'app/models/media_attachment.rb'
- 'app/models/notification.rb'
- 'app/models/poll.rb'
- 'app/presenters/account_relationships_presenter.rb'
- 'app/services/keys/claim_service.rb'
- 'app/services/keys/query_service.rb'
- 'app/workers/web/push_notification_worker.rb'
- 'db/post_migrate/20200917193528_migrate_notifications_type.rb'
- 'lib/sanitize_ext/sanitize_config.rb'
- 'lib/tasks/auto_annotate_models.rake'
- 'lib/tasks/mastodon.rake'
- 'spec/models/admin/account_action_spec.rb'
- 'spec/models/concerns/account_interactions_spec.rb'

# Offense count: 581
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
Expand Down
1 change: 1 addition & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/scm/git'
Expand Down
1 change: 1 addition & 0 deletions app/controllers/api/v1/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def unfollow

def set_or_create_tag
return not_found unless Tag::HASHTAG_NAME_RE.match?(params[:id])

@tag = Tag.find_normalized(params[:id]) || Tag.new(name: Tag.normalize(params[:id]), display_name: params[:id])
end
end
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def current_session

def current_theme
return Setting.theme unless Themes.instance.names.include? current_user&.setting_theme

current_user.setting_theme
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/session_tracking_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module SessionTrackingConcern

def set_session_activity
return unless session_needs_update?

current_session.touch
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/signature_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def verify_body_digest!
end

raise SignatureVerificationError, "Invalid Digest value. The provided Digest value is not a SHA-256 digest. Given digest: #{sha256[1]}" if digest_size != 32

raise SignatureVerificationError, "Invalid Digest value. Computed SHA-256 digest: #{body_digest}; given: #{sha256[1]}"
end

Expand Down
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def class_for_scope(scope)

def can?(action, record)
return false if record.nil?

policy(record).public_send("#{action}?")
end

Expand Down
1 change: 1 addition & 0 deletions app/helpers/languages_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ModuleLength, Style/WordArray

module LanguagesHelper
Expand Down
1 change: 1 addition & 0 deletions app/lib/activitypub/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def follow_from_object
def fetch_remote_original_status
if object_uri.start_with?('http')
return if ActivityPub::TagManager.instance.local_uri?(object_uri)

ActivityPub::FetchRemoteStatusService.new.call(object_uri, id: true, on_behalf_of: @account.followers.local.first, request_id: @options[:request_id])
elsif @object['url'].present?
::FetchRemoteStatusService.new.call(@object['url'], request_id: @options[:request_id])
Expand Down
2 changes: 1 addition & 1 deletion app/lib/activitypub/linked_data_signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def verify_actor!

def sign!(creator, sign_with: nil)
options = {
'type' => 'RsaSignature2017',
'type' => 'RsaSignature2017',
'creator' => ActivityPub::TagManager.instance.key_uri_for(creator),
'created' => Time.now.utc.iso8601,
}
Expand Down
2 changes: 2 additions & 0 deletions app/lib/activitypub/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def url_for(target)
target.instance_actor? ? about_more_url(instance_actor: true) : short_account_url(target)
when :note, :comment, :activity
return activity_account_status_url(target.account, target) if target.reblog?

short_account_status_url(target.account, target)
end
end
Expand All @@ -38,6 +39,7 @@ def uri_for(target)
target.instance_actor? ? instance_actor_url : account_url(target)
when :note, :comment, :activity
return activity_account_status_url(target.account, target) if target.reblog?

account_status_url(target.account, target)
when :emoji
emoji_url(target)
Expand Down
32 changes: 16 additions & 16 deletions app/lib/ostatus/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ class OStatus::TagManager
include RoutingHelper

VERBS = {
post: 'http://activitystrea.ms/schema/1.0/post',
share: 'http://activitystrea.ms/schema/1.0/share',
favorite: 'http://activitystrea.ms/schema/1.0/favorite',
unfavorite: 'http://activitystrea.ms/schema/1.0/unfavorite',
delete: 'http://activitystrea.ms/schema/1.0/delete',
follow: 'http://activitystrea.ms/schema/1.0/follow',
post: 'http://activitystrea.ms/schema/1.0/post',
share: 'http://activitystrea.ms/schema/1.0/share',
favorite: 'http://activitystrea.ms/schema/1.0/favorite',
unfavorite: 'http://activitystrea.ms/schema/1.0/unfavorite',
delete: 'http://activitystrea.ms/schema/1.0/delete',
follow: 'http://activitystrea.ms/schema/1.0/follow',
request_friend: 'http://activitystrea.ms/schema/1.0/request-friend',
authorize: 'http://activitystrea.ms/schema/1.0/authorize',
reject: 'http://activitystrea.ms/schema/1.0/reject',
unfollow: 'http://ostatus.org/schema/1.0/unfollow',
block: 'http://mastodon.social/schema/1.0/block',
unblock: 'http://mastodon.social/schema/1.0/unblock',
authorize: 'http://activitystrea.ms/schema/1.0/authorize',
reject: 'http://activitystrea.ms/schema/1.0/reject',
unfollow: 'http://ostatus.org/schema/1.0/unfollow',
block: 'http://mastodon.social/schema/1.0/block',
unblock: 'http://mastodon.social/schema/1.0/unblock',
}.freeze

TYPES = {
activity: 'http://activitystrea.ms/schema/1.0/activity',
note: 'http://activitystrea.ms/schema/1.0/note',
comment: 'http://activitystrea.ms/schema/1.0/comment',
person: 'http://activitystrea.ms/schema/1.0/person',
activity: 'http://activitystrea.ms/schema/1.0/activity',
note: 'http://activitystrea.ms/schema/1.0/note',
comment: 'http://activitystrea.ms/schema/1.0/comment',
person: 'http://activitystrea.ms/schema/1.0/person',
collection: 'http://activitystrea.ms/schema/1.0/collection',
group: 'http://activitystrea.ms/schema/1.0/group',
group: 'http://activitystrea.ms/schema/1.0/group',
}.freeze

COLLECTIONS = {
Expand Down
1 change: 1 addition & 0 deletions app/lib/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def body_with_limit(limit = 1.megabyte)

contents = truncated_body(limit)
raise Mastodon::LengthValidationError if contents.bytesize > limit

contents
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/lib/settings/scoped_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def all_as_records

Setting.default_settings.each do |key, default_value|
next if records.key?(key) || default_value.is_a?(Hash)

records[key] = Setting.new(var: key, value: default_value)
end

Expand All @@ -54,6 +55,7 @@ def [](key)
if db_val
default_value = ScopedSettings.default_settings[key]
return default_value.with_indifferent_access.merge!(db_val.value) if default_value.is_a?(Hash)

db_val.value
else
ScopedSettings.default_settings[key]
Expand Down
1 change: 1 addition & 0 deletions app/lib/status_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize(status, account, preloaded_relations = {})

def filtered?
return false if !account.nil? && account.id == status.account_id

blocked_by_policy? || (account_present? && filtered_status?) || silenced_account?
end

Expand Down
1 change: 1 addition & 0 deletions app/lib/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def normalize_domain(domain)
def local_url?(url)
uri = Addressable::URI.parse(url).normalize
return false unless uri.host

domain = uri.host + (uri.port ? ":#{uri.port}" : '')

TagManager.instance.web_domain?(domain)
Expand Down
1 change: 1 addition & 0 deletions app/lib/webfinger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def body_from_webfinger(url = standard_url, use_fallback = true)
if res.code == 200
body = res.body_with_limit
raise Webfinger::Error, "Request for #{@uri} returned empty response" if body.empty?

body
elsif res.code == 404 && use_fallback
body_from_host_meta
Expand Down
2 changes: 2 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: accounts
Expand Down Expand Up @@ -539,6 +540,7 @@ def emojis

def ensure_keys!
return unless local? && private_key.blank? && public_key.blank?

generate_keys
save!
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/account/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def initialize(account, attributes)
@account = account

super(
name: sanitize(attributes['name']),
value: sanitize(attributes['value']),
name: sanitize(attributes['name']),
value: sanitize(attributes['value']),
verified_at: attributes['verified_at']&.to_datetime,
)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/account_conversation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: account_conversations
Expand Down Expand Up @@ -107,6 +108,7 @@ def set_last_status

def push_to_streaming_api
return if destroyed? || !subscribed_to_timeline?

PushConversationWorker.perform_async(id)
end

Expand Down
1 change: 1 addition & 0 deletions app/models/account_domain_block.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: account_domain_blocks
Expand Down
1 change: 1 addition & 0 deletions app/models/account_moderation_note.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: account_moderation_notes
Expand Down
1 change: 1 addition & 0 deletions app/models/account_note.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: account_notes
Expand Down
1 change: 1 addition & 0 deletions app/models/account_pin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: account_pins
Expand Down
Loading

0 comments on commit 717683d

Please sign in to comment.