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

@@ -40,7 +40,7 @@ class Api::V1::Timelines::PublicController < Api::BaseController
only_media: truthy_param?(:only_media),
allow_local_only: truthy_param?(:allow_local_only),
with_replies: Setting.show_replies_in_public_timelines,
with_reblogs: Setting.show_reblogs_in_public_timelines,
with_reblogs: Setting.show_reblogs_in_public_timelines
)
end

View File

@@ -15,12 +15,6 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
skip_before_action :require_functional!
def new
super
resource.email = current_user.unconfirmed_email || current_user.email if user_signed_in?
end
def show
old_session_values = session.to_hash
reset_session
@@ -29,6 +23,12 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
super
end
def new
super
resource.email = current_user.unconfirmed_email || current_user.email if user_signed_in?
end
def confirm_captcha
check_captcha! do |message|
flash.now[:alert] = message
@@ -51,6 +51,7 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
# step.
confirmation_token = params[:confirmation_token]
return if confirmation_token.nil?
@confirmation_user = User.find_first_by_auth_conditions(confirmation_token: confirmation_token)
end

View File

@@ -12,9 +12,7 @@ class Settings::FlavoursController < Settings::BaseController
end
def show
unless Themes.instance.flavours.include?(params[:flavour]) || (params[:flavour] == current_flavour)
redirect_to action: 'show', flavour: current_flavour
end
redirect_to action: 'show', flavour: current_flavour unless Themes.instance.flavours.include?(params[:flavour]) || (params[:flavour] == current_flavour)
@listing = Themes.instance.flavours
@selected = params[:flavour]

View File

@@ -28,7 +28,7 @@ module AccountsHelper
end
def hide_followers_count?(account)
Setting.hide_followers_count || account.user&.settings['hide_followers_count']
Setting.hide_followers_count || account.user&.settings&.[]('hide_followers_count')
end
def account_description(account)

View File

@@ -15,6 +15,7 @@ class AdvancedTextFormatter < TextFormatter
def autolink(link, link_type)
return link if link_type == :email
@format_link.call(link)
end
end

View File

@@ -306,6 +306,7 @@ class FeedManager
statuses.each do |status|
next if filter_from_direct?(status, account)
added += 1 if add_to_feed(:direct, account.id, status)
end
@@ -459,6 +460,7 @@ class FeedManager
# @return [Boolean]
def filter_from_direct?(status, receiver_id)
return false if receiver_id == status.account_id
filter_from_mentions?(status, receiver_id)
end

View File

@@ -7,24 +7,23 @@ class Themes
include Singleton
def initialize
core = YAML.load_file(Rails.root.join('app', 'javascript', 'core', 'theme.yml'))
core['pack'] = Hash.new unless core['pack']
core['pack'] = {} unless core['pack']
result = Hash.new
Dir.glob(Rails.root.join('app', 'javascript', 'flavours', '*', 'theme.yml')) do |path|
data = YAML.load_file(path)
result = {}
Rails.root.glob('app/javascript/flavours/*/theme.yml') do |pathname|
data = YAML.load_file(pathname)
next unless data['pack']
dir = File.dirname(path)
name = File.basename(dir)
dir = pathname.dirname
name = dir.basename.to_s
locales = []
screenshots = []
if data['locales']
Dir.glob(File.join(dir, data['locales'], '*.{js,json}')) do |locale|
localeName = File.basename(locale, File.extname(locale))
locales.push(localeName) unless localeName.match(/defaultMessages|whitelist|index/)
locale_name = File.basename(locale, File.extname(locale))
locales.push(locale_name) unless /defaultMessages|whitelist|index/.match?(locale_name)
end
end
@@ -43,34 +42,30 @@ class Themes
result[name] = data
end
Dir.glob(Rails.root.join('app', 'javascript', 'skins', '*', '*')) do |path|
ext = File.extname(path)
skin = File.basename(path)
name = File.basename(File.dirname(path))
Rails.root.glob('app/javascript/skins/*/*') do |pathname|
ext = pathname.extname.to_s
skin = pathname.basename.to_s
name = pathname.dirname.basename.to_s
next unless result[name]
if File.directory?(path)
if pathname.directory?
pack = []
Dir.glob(File.join(path, '*.{css,scss}')) do |sheet|
pack.push(File.basename(sheet, File.extname(sheet)))
pathname.glob('*.{css,scss}') do |sheet|
pack.push(sheet.basename(sheet.extname).to_s)
end
elsif ext.match(/^\.s?css$/i)
skin = File.basename(path, ext)
elsif /^\.s?css$/i.match?(ext)
skin = pathname.basename(ext).to_s
pack = ['common']
end
if skin != 'default'
result[name]['skin'][skin] = pack
end
result[name]['skin'][skin] = pack if skin != 'default'
end
@core = core
@conf = result
end
def core
@core
end
attr_reader :core
def flavour(name)
@conf[name]
@@ -86,7 +81,7 @@ class Themes
def flavours_and_skins
flavours.map do |flavour|
[flavour, skins_for(flavour).map{ |skin| [flavour, skin] }]
[flavour, skins_for(flavour).map { |skin| [flavour, skin] }]
end
end
end

View File

@@ -4,9 +4,8 @@ class DirectFeed < Feed
include Redisable
def initialize(account)
@type = :direct
@id = account.id
@account = account
super(:direct, account.id)
end
def get(limit, max_id = nil, since_id = nil, min_id = nil)
@@ -19,10 +18,12 @@ class DirectFeed < Feed
private
def from_database(limit, max_id, since_id, min_id)
# TODO: _min_id is not actually handled by `as_direct_timeline`
def from_database(limit, max_id, since_id, _min_id)
loop do
statuses = Status.as_direct_timeline(@account, limit, max_id, since_id, min_id)
statuses = Status.as_direct_timeline(@account, limit, max_id, since_id)
return statuses if statuses.empty?
max_id = statuses.last.id
statuses = statuses.reject { |status| FeedManager.instance.filter?(:direct, status, @account) }
return statuses unless statuses.empty?

View File

@@ -338,7 +338,7 @@ class Status < ApplicationRecord
visibilities.keys - %w(direct limited)
end
def as_direct_timeline(account, limit = 20, max_id = nil, since_id = nil, cache_ids = false)
def as_direct_timeline(account, limit = 20, max_id = nil, since_id = nil)
# direct timeline is mix of direct message from_me and to_me.
# 2 queries are executed with pagination.
# constant expression using arel_table is required for partial index
@@ -369,14 +369,9 @@ class Status < ApplicationRecord
query_to_me = query_to_me.where('mentions.status_id > ?', since_id)
end
if cache_ids
# returns array of cache_ids object that have id and updated_at
(query_from_me.cache_ids.to_a + query_to_me.cache_ids.to_a).uniq(&:id).sort_by(&:id).reverse.take(limit)
else
# returns ActiveRecord.Relation
items = (query_from_me.select(:id).to_a + query_to_me.select(:id).to_a).uniq(&:id).sort_by(&:id).reverse.take(limit)
Status.where(id: items.map(&:id))
end
# returns ActiveRecord.Relation
items = (query_from_me.select(:id).to_a + query_to_me.select(:id).to_a).uniq(&:id).sort_by(&:id).reverse.take(limit)
Status.where(id: items.map(&:id))
end
def favourites_map(status_ids, account_id)
@@ -553,9 +548,9 @@ class Status < ApplicationRecord
end
def set_locality
if account.domain.nil? && !attribute_changed?(:local_only)
self.local_only = marked_local_only?
end
return unless account.domain.nil? && !attribute_changed?(:local_only)
self.local_only = marked_local_only?
end
def set_conversation

View File

@@ -244,7 +244,6 @@ class User < ApplicationRecord
end
def functional?
functional_or_moved?
end

View File

@@ -32,6 +32,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
def id
raise Mastodon::NotPermittedError, 'Local-only statuses should not be serialized' if object.local_only? && !instance_options[:allow_local_only]
ActivityPub::TagManager.instance.uri_for(object)
end

View File

@@ -91,7 +91,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
end
def followers_count
(Setting.hide_followers_count || object.user&.setting_hide_followers_count) ? -1 : object.followers_count
Setting.hide_followers_count || object.user&.setting_hide_followers_count ? -1 : object.followers_count
end
def display_name

View File

@@ -2,7 +2,7 @@
class REST::MuteSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :id, :account, :target_account, :created_at, :hide_notifications
def account
@@ -12,4 +12,4 @@ class REST::MuteSerializer < ActiveModel::Serializer
def target_account
REST::AccountSerializer.new(object.target_account)
end
end
end

View File

@@ -13,7 +13,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
attribute :muted, if: :current_user?
attribute :bookmarked, if: :current_user?
attribute :pinned, if: :pinnable?
attribute :local_only if :local?
attribute :local_only, if: :local?
has_many :filtered, serializer: REST::FilterResultSerializer, if: :current_user?
attribute :content, unless: :source_requested?
@@ -32,6 +32,8 @@ class REST::StatusSerializer < ActiveModel::Serializer
has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer
has_one :preloadable_poll, key: :poll, serializer: REST::PollSerializer
delegate :local?, to: :object
def id
object.id.to_s
end

View File

@@ -154,7 +154,7 @@ class BackupService < BaseService
object,
serializer: serializer,
adapter: ActivityPub::Adapter,
allow_local_only: true,
allow_local_only: true
).as_json
end

View File

@@ -116,7 +116,7 @@ class FanOutOnWriteService < BaseService
end
def deliver_to_direct_timelines!
FeedInsertWorker.push_bulk(@status.mentions.includes(:account).map(&:account).select { |mentioned_account| mentioned_account.local? }) do |account|
FeedInsertWorker.push_bulk(@status.mentions.includes(:account).map(&:account).select(&:local?)) do |account|
[@status.id, account.id, 'direct', { 'update' => update? }]
end
end

View File

@@ -61,17 +61,22 @@ class PostStatusService < BaseService
private
def preprocess_attributes!
if @text.blank? && @options[:spoiler_text].present?
@text = '.'
if @media&.find(&:video?) || @media&.find(&:gifv?)
@text = '📹'
elsif @media&.find(&:audio?)
@text = '🎵'
elsif @media&.find(&:image?)
@text = '🖼'
end
def fill_blank_text!
return unless @text.blank? && @options[:spoiler_text].present?
if @media&.any?(&:video?) || @media&.any?(&:gifv?)
@text = '📹'
elsif @media&.any?(&:audio?)
@text = '🎵'
elsif @media&.any?(&:image?)
@text = '🖼'
else
@text = '.'
end
end
def preprocess_attributes!
fill_blank_text!
@sensitive = (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present?
@visibility = @options[:visibility] || @account.user&.setting_default_privacy
@visibility = :unlisted if @visibility&.to_sym == :public && @account.silenced?

View File

@@ -7,6 +7,6 @@ class StatusPinValidator < ActiveModel::Validator
pin.errors.add(:base, I18n.t('statuses.pin_errors.reblog')) if pin.status.reblog?
pin.errors.add(:base, I18n.t('statuses.pin_errors.ownership')) if pin.account_id != pin.status.account_id
pin.errors.add(:base, I18n.t('statuses.pin_errors.direct')) if pin.status.direct_visibility?
pin.errors.add(:base, I18n.t('statuses.pin_errors.limit')) if pin.account.status_pins.count >= MAX_PINNED && pin.account.local?
pin.errors.add(:base, I18n.t('statuses.pin_errors.limit')) if pin.account.status_pins.count >= MAX_PINNED && pin.account.local?
end
end