Fix all rubocop warnings

This commit is contained in:
Yamagishi Kazutoshi 2022-06-28 12:48:43 +00:00 committed by GitHub
parent 05e39dc619
commit bf851133ae
48 changed files with 124 additions and 97 deletions

View file

@ -30,7 +30,7 @@ class Api::V1::AccountsController < Api::BaseController
self.response_body = Oj.dump(response.body)
self.status = response.status
rescue ActiveRecord::RecordInvalid => e
render json: ValidationErrorFormatter.new(e, :'account.username' => :username, :'invite_request.text' => :reason).as_json, status: :unprocessable_entity
render json: ValidationErrorFormatter.new(e, 'account.username': :username, 'invite_request.text': :reason).as_json, status: :unprocessable_entity
end
def follow

View file

@ -122,7 +122,7 @@ class Auth::SessionsController < Devise::SessionsController
redirect_to new_user_session_path, alert: I18n.t('devise.failure.timeout')
end
def set_attempt_session(user)
def set_attempt_session(user) # rubocop:disable Naming/AccessorMethodName
session[:attempt_user_id] = user.id
session[:attempt_user_updated_at] = user.updated_at.to_s
end

View file

@ -112,7 +112,7 @@ module JsonLdHelper
if value.is_a?(Hash) && compacted_value.is_a?(Hash)
patch_for_forwarding!(value, compacted_value)
elsif value.is_a?(Array)
compacted_value = [compacted_value] unless compacted_value.is_a?(Array)
compacted_value = [compacted_value] unless compacted_value.is_a?(Array) # rubocop:disable Style/ArrayCoercion
return if value.size != compacted_value.size
compacted[key] = value.zip(compacted_value).map do |v, vc|
@ -143,7 +143,7 @@ module JsonLdHelper
def safe_for_forwarding?(original, compacted)
original.without('@context', 'signature').all? do |key, value|
compacted_value = compacted[key]
return false unless value.class == compacted_value.class
return false unless value.class == compacted_value.class # rubocop:disable Style/ClassEqualityComparison
if value.is_a?(Hash)
safe_for_forwarding?(value, compacted_value)

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
module LanguagesHelper
module LanguagesHelper # rubocop:disable Metrics/ModuleLength
ISO_639_1 = {
aa: ['Afar', 'Afaraf'].freeze,
ab: ['Abkhaz', 'аҧсуа бызшәа'].freeze,

View file

@ -13,7 +13,7 @@ module ActivityPub::CaseTransform
when Symbol then camel_lower(value.to_s).to_sym
when String
camel_lower_cache[value] ||= if value.start_with?('_:')
'_:' + value.gsub(/\A_:/, '').underscore.camelize(:lower)
"_:#{value.gsub(/\A_:/, '').underscore.camelize(:lower)}"
else
value.underscore.camelize(:lower)
end

View file

@ -62,7 +62,7 @@ class EmojiFormatter
end
end
result << html[last_index..-1]
result << html[last_index..]
result.html_safe # rubocop:disable Rails/OutputSafety
end

View file

@ -29,7 +29,7 @@ module Extractor
text.scan(Account::MENTION_RE) do |screen_name, _|
match_data = $LAST_MATCH_INFO
after = $'
after = Regexp.last_match.post_match
unless Twitter::TwitterText::Regex[:end_mention_match].match?(after)
_, domain = screen_name.split('@')
@ -64,7 +64,7 @@ module Extractor
match_data = $LAST_MATCH_INFO
start_position = match_data.char_begin(1) - 1
end_position = match_data.char_end(1)
after = $'
after = Regexp.last_match.post_match
if %r{\A://}.match?(after)
hash_text.match(/(.+)(https?\Z)/) do |matched|

View file

@ -7,8 +7,8 @@ class RedisConfiguration
@pool = ConnectionPool.new(size: new_pool_size) { new.connection }
end
def with
pool.with { |redis| yield redis }
def with(&block)
pool.with(&block)
end
def pool

View file

@ -64,7 +64,7 @@ class TextFormatter
indices.last
end
result << h(text[last_index..-1])
result << h(text[last_index..])
result
end
@ -75,8 +75,8 @@ class TextFormatter
prefix = url.match(URL_PREFIX_REGEX).to_s
display_url = url[prefix.length, 30]
suffix = url[prefix.length + 30..-1]
cutoff = url[prefix.length..-1].length > 30
suffix = url[prefix.length + 30..]
cutoff = url[prefix.length..].length > 30
<<~HTML.squish
<a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a>

View file

@ -53,7 +53,7 @@ class TOCGenerator
next unless LISTED_ELEMENTS.include?(node.name)
depth = node.name[1..-1]
depth = node.name[1..]
latest_section = @headers.last
if latest_section.nil? || latest_section.depth >= depth

View file

@ -14,7 +14,7 @@ class UserSettingsDecorator
private
def process_update
def process_update # rubocop:disable Metrics/AbcSize
user.settings['notification_emails'] = merged_notification_emails if change?('notification_emails')
user.settings['interactions'] = merged_interactions if change?('interactions')
user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy')

View file

@ -19,7 +19,7 @@ class ValidationErrorFormatter
messages = errors.messages[attribute_name]
h[@aliases[attribute_name] || attribute_name] = attribute_errors.map.with_index do |error, index|
{ error: 'ERR_' + error[:error].to_s.upcase, description: messages[index] }
{ error: "ERR_#{error[:error].to_s.upcase}", description: messages[index] }
end
end

View file

@ -99,7 +99,7 @@ class Webfinger
end
def standard_url
if @domain.end_with? ".onion"
if @domain.end_with? '.onion'
"http://#{@domain}/.well-known/webfinger?resource=#{@uri}"
else
"https://#{@domain}/.well-known/webfinger?resource=#{@uri}"
@ -107,7 +107,7 @@ class Webfinger
end
def host_meta_url
if @domain.end_with? ".onion"
if @domain.end_with? '.onion'
"http://#{@domain}/.well-known/host-meta"
else
"https://#{@domain}/.well-known/host-meta"

View file

@ -9,9 +9,7 @@ class ApplicationMailer < ActionMailer::Base
protected
def locale_for_account(account)
I18n.with_locale(account.user_locale || I18n.default_locale) do
yield
end
def locale_for_account(account, &block)
I18n.with_locale(account.user_locale || I18n.default_locale, &block)
end
end

View file

@ -25,7 +25,7 @@ class AccountAlias < ApplicationRecord
def acct=(val)
val = val.to_s.strip
super(val.start_with?('@') ? val[1..-1] : val)
super(val.start_with?('@') ? val[1..] : val)
end
def pretty_acct

View file

@ -16,6 +16,7 @@
#
class AccountWarning < ApplicationRecord
# rubocop:disable Lint/RedundantCopDisableDirective, Layout/FirstHashElementIndentation
enum action: {
none: 0,
disable: 1_000,
@ -25,6 +26,7 @@ class AccountWarning < ApplicationRecord
silence: 3_000,
suspend: 4_000,
}, _suffix: :action
# rubocop:enable Lint/RedundantCopDisableDirective, Layout/FirstHashElementIndentation
belongs_to :account, inverse_of: :account_warnings
belongs_to :target_account, class_name: 'Account', inverse_of: :strikes

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
module AccountInteractions
module AccountInteractions # rubocop:disable Metrics/ModuleLength
extend ActiveSupport::Concern
class_methods do

View file

@ -17,7 +17,7 @@ module Expireable
end
def expires_in=(interval)
self.expires_at = interval.present? ? interval.to_i.seconds.from_now : nil
self.expires_at = interval.present? ? interval.to_i.seconds.from_now : nil
@expires_in = interval
end

View file

@ -46,7 +46,7 @@ class CustomEmoji < ApplicationRecord
scope :local, -> { where(domain: nil) }
scope :remote, -> { where.not(domain: nil) }
scope :alphabetic, -> { order(domain: :asc, shortcode: :asc) }
scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches('%.' + domain))) }
scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches("%.#{domain}"))) }
scope :listed, -> { local.where(disabled: false).where(visible_in_picker: true) }
remotable_attachment :image, LIMIT

View file

@ -63,7 +63,7 @@ class DomainBlock < ApplicationRecord
uri = Addressable::URI.new.tap { |u| u.host = domain.strip.gsub(/[\/]/, '') }
segments = uri.normalized_host.split('.')
variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }
variants = segments.map.with_index { |_, i| segments[i..].join('.') }
where(domain: variants).order(Arel.sql('char_length(domain) desc')).first
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError

View file

@ -52,6 +52,6 @@ class PreviewCardProvider < ApplicationRecord
def self.matching_domain(domain)
segments = domain.split('.')
where(domain: segments.map.with_index { |_, i| segments[i..-1].join('.') }).order(Arel.sql('char_length(domain) desc')).first
where(domain: segments.map.with_index { |_, i| segments[i..].join('.') }).order(Arel.sql('char_length(domain) desc')).first
end
end

View file

@ -2,7 +2,7 @@
class ActivityPub::OutboxSerializer < ActivityPub::CollectionSerializer
def self.serializer_for(model, options)
if model.class.name == 'ActivityPub::ActivityPresenter'
if model.instance_of?(ActivityPub::ActivityPresenter)
ActivityPub::ActivitySerializer
else
super

View file

@ -53,7 +53,7 @@ class BackupService < BaseService
end
end
archive_filename = ['archive', Time.now.utc.strftime('%Y%m%d%H%M%S'), SecureRandom.hex(16)].join('-') + '.tar.gz'
archive_filename = "#{['archive', Time.now.utc.strftime('%Y%m%d%H%M%S'), SecureRandom.hex(16)].join('-')}.tar.gz"
@backup.dump = ActionDispatch::Http::UploadedFile.new(tempfile: tmp_file, filename: archive_filename)
@backup.processed = true
@ -86,14 +86,14 @@ class BackupService < BaseService
def dump_actor!(tar)
actor = serialize(account, ActivityPub::ActorSerializer)
actor[:icon][:url] = 'avatar' + File.extname(actor[:icon][:url]) if actor[:icon]
actor[:image][:url] = 'header' + File.extname(actor[:image][:url]) if actor[:image]
actor[:icon][:url] = "avatar#{File.extname(actor[:icon][:url])}" if actor[:icon]
actor[:image][:url] = "header#{File.extname(actor[:image][:url])}" if actor[:image]
actor[:outbox] = 'outbox.json'
actor[:likes] = 'likes.json'
actor[:bookmarks] = 'bookmarks.json'
download_to_tar(tar, account.avatar, 'avatar' + File.extname(account.avatar.path)) if account.avatar.exists?
download_to_tar(tar, account.header, 'header' + File.extname(account.header.path)) if account.header.exists?
download_to_tar(tar, account.avatar, "avatar#{File.extname(account.avatar.path)}") if account.avatar.exists?
download_to_tar(tar, account.header, "header#{File.extname(account.header.path)}") if account.header.exists?
json = Oj.dump(actor)

View file

@ -45,7 +45,7 @@ class FetchLinkCardService < BaseService
def html
return @html if defined?(@html)
Request.new(:get, @url).add_headers('Accept' => 'text/html', 'User-Agent' => Mastodon::Version.user_agent + ' Bot').perform do |res|
Request.new(:get, @url).add_headers('Accept' => 'text/html', 'User-Agent' => '${Mastodon::Version.user_agent} Bot').perform do |res|
# We follow redirects, and ideally we want to save the preview card for
# the destination URL and not any link shortener in-between, so here
# we set the URL to the one of the last response in the redirect chain

View file

@ -21,8 +21,8 @@ class ExistingUsernameValidator < ActiveModel::EachValidator
if options[:multiple]
record.errors.add(attribute, I18n.t('existing_username_validator.not_found_multiple', usernames: usernames_with_no_accounts.join(', '))) if usernames_with_no_accounts.any?
else
record.errors.add(attribute, I18n.t('existing_username_validator.not_found')) if usernames_with_no_accounts.any? || usernames_and_domains.size > 1
elsif usernames_with_no_accounts.any? || usernames_and_domains.size > 1
record.errors.add(attribute, I18n.t('existing_username_validator.not_found'))
end
end
end

View file

@ -53,7 +53,7 @@ class StatusLengthValidator < ActiveModel::Validator
entity[:indices].last
end
result << str[last_index..-1]
result << str[last_index..]
result
end
end