Fix rubocop config and warnings (#15503)

* disable NewCops

* update TargetRubyVersion

* Fix Lint/MissingSuper for ActiveModelSerializers::Model

* Fix Lint/MissingSuper for feed

* Fix Lint/FloatComparison

* Do not use instance variables
This commit is contained in:
abcang 2021-01-07 17:40:55 +09:00 committed by GitHub
parent 066dbe1e69
commit efffdd3778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 59 additions and 59 deletions

View File

@ -2,7 +2,8 @@ require:
- rubocop-rails - rubocop-rails
AllCops: AllCops:
TargetRubyVersion: 2.4 TargetRubyVersion: 2.5
NewCops: disable
Exclude: Exclude:
- 'spec/**/*' - 'spec/**/*'
- 'db/**/*' - 'db/**/*'

View File

@ -385,15 +385,17 @@ class Account < ApplicationRecord
end end
class Field < ActiveModelSerializers::Model class Field < ActiveModelSerializers::Model
attributes :name, :value, :verified_at, :account, :errors attributes :name, :value, :verified_at, :account
def initialize(account, attributes) def initialize(account, attributes)
@account = account @original_field = attributes
@attributes = attributes string_limit = account.local? ? 255 : 2047
@name = attributes['name'].strip[0, string_limit] super(
@value = attributes['value'].strip[0, string_limit] account: account,
@verified_at = attributes['verified_at']&.to_datetime name: attributes['name'].strip[0, string_limit],
@errors = {} value: attributes['value'].strip[0, string_limit],
verified_at: attributes['verified_at']&.to_datetime,
)
end end
def verified? def verified?
@ -415,22 +417,12 @@ class Account < ApplicationRecord
end end
def mark_verified! def mark_verified!
@verified_at = Time.now.utc self.verified_at = Time.now.utc
@attributes['verified_at'] = @verified_at @original_field['verified_at'] = verified_at
end end
def to_h def to_h
{ name: @name, value: @value, verified_at: @verified_at } { name: name, value: value, verified_at: verified_at }
end
private
def string_limit
if account.local?
255
else
2047
end
end end
end end

View File

@ -2,12 +2,11 @@
class HomeFeed < Feed class HomeFeed < Feed
def initialize(account) def initialize(account)
@type = :home
@id = account.id
@account = account @account = account
super(:home, account.id)
end end
def regenerating? def regenerating?
redis.exists?("account:#{@id}:regeneration") redis.exists?("account:#{@account.id}:regeneration")
end end
end end

View File

@ -2,7 +2,6 @@
class ListFeed < Feed class ListFeed < Feed
def initialize(list) def initialize(list)
@type = :list super(:list, list.id)
@id = list.id
end end
end end

View File

@ -73,10 +73,12 @@ class Poll < ApplicationRecord
attributes :id, :title, :votes_count, :poll attributes :id, :title, :votes_count, :poll
def initialize(poll, id, title, votes_count) def initialize(poll, id, title, votes_count)
@poll = poll super(
@id = id poll: poll,
@title = title id: id,
@votes_count = votes_count title: title,
votes_count: votes_count,
)
end end
end end

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
class PublicFeed < Feed class PublicFeed
# @param [Account] account # @param [Account] account
# @param [Hash] options # @param [Hash] options
# @option [Boolean] :with_replies # @option [Boolean] :with_replies
@ -33,28 +33,30 @@ class PublicFeed < Feed
private private
attr_reader :account, :options
def with_reblogs? def with_reblogs?
@options[:with_reblogs] options[:with_reblogs]
end end
def with_replies? def with_replies?
@options[:with_replies] options[:with_replies]
end end
def local_only? def local_only?
@options[:local] options[:local]
end end
def remote_only? def remote_only?
@options[:remote] options[:remote]
end end
def account? def account?
@account.present? account.present?
end end
def media_only? def media_only?
@options[:only_media] options[:only_media]
end end
def public_scope def public_scope
@ -82,9 +84,9 @@ class PublicFeed < Feed
end end
def account_filters_scope def account_filters_scope
Status.not_excluded_by_account(@account).tap do |scope| Status.not_excluded_by_account(account).tap do |scope|
scope.merge!(Status.not_domain_blocked_by_account(@account)) unless local_only? scope.merge!(Status.not_domain_blocked_by_account(account)) unless local_only?
scope.merge!(Status.in_chosen_languages(@account)) if @account.chosen_languages.present? scope.merge!(Status.in_chosen_languages(account)) if account.chosen_languages.present?
end end
end end
end end

View File

@ -13,9 +13,8 @@ class TagFeed < PublicFeed
# @option [Boolean] :remote # @option [Boolean] :remote
# @option [Boolean] :only_media # @option [Boolean] :only_media
def initialize(tag, account, options = {}) def initialize(tag, account, options = {})
@tag = tag @tag = tag
@account = account super(account, options)
@options = options
end end
# @param [Integer] limit # @param [Integer] limit
@ -40,15 +39,15 @@ class TagFeed < PublicFeed
private private
def tagged_with_any_scope def tagged_with_any_scope
Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(@options[:any]))) Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(options[:any])))
end end
def tagged_with_all_scope def tagged_with_all_scope
Status.group(:id).tagged_with_all(tags_for(@options[:all])) Status.group(:id).tagged_with_all(tags_for(options[:all]))
end end
def tagged_with_none_scope def tagged_with_none_scope
Status.group(:id).tagged_with_none(tags_for(@options[:none])) Status.group(:id).tagged_with_none(tags_for(options[:none]))
end end
def tags_for(names) def tags_for(names)

View File

@ -8,11 +8,13 @@ class Keys::ClaimService < BaseService
:key, :signature :key, :signature
def initialize(account, device_id, key_attributes = {}) def initialize(account, device_id, key_attributes = {})
@account = account super(
@device_id = device_id account: account,
@key_id = key_attributes[:key_id] device_id: device_id,
@key = key_attributes[:key] key_id: key_attributes[:key_id],
@signature = key_attributes[:signature] key: key_attributes[:key],
signature: key_attributes[:signature],
)
end end
end end

View File

@ -7,8 +7,10 @@ class Keys::QueryService < BaseService
attributes :account, :devices attributes :account, :devices
def initialize(account, devices) def initialize(account, devices)
@account = account super(
@devices = devices || [] account: account,
devices: devices || [],
)
end end
def find(device_id) def find(device_id)
@ -20,11 +22,13 @@ class Keys::QueryService < BaseService
attributes :device_id, :name, :identity_key, :fingerprint_key attributes :device_id, :name, :identity_key, :fingerprint_key
def initialize(attributes = {}) def initialize(attributes = {})
@device_id = attributes[:device_id] super(
@name = attributes[:name] device_id: attributes[:device_id],
@identity_key = attributes[:identity_key] name: attributes[:name],
@fingerprint_key = attributes[:fingerprint_key] identity_key: attributes[:identity_key],
@claim_url = attributes[:claim_url] fingerprint_key: attributes[:fingerprint_key],
)
@claim_url = attributes[:claim_url]
end end
def valid_claim_url? def valid_claim_url?

View File

@ -142,7 +142,7 @@ module Paperclip
g = 0.0 g = 0.0
b = 0.0 b = 0.0
if s == 0.0 if s.zero?
r = l.to_f r = l.to_f
g = l.to_f g = l.to_f
b = l.to_f # achromatic b = l.to_f # achromatic