Skip to content

Commit efffdd3

Browse files
authored
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
1 parent 066dbe1 commit efffdd3

10 files changed

+59
-59
lines changed

.rubocop.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ require:
22
- rubocop-rails
33

44
AllCops:
5-
TargetRubyVersion: 2.4
5+
TargetRubyVersion: 2.5
6+
NewCops: disable
67
Exclude:
78
- 'spec/**/*'
89
- 'db/**/*'

app/models/account.rb

+12-20
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,17 @@ def synchronization_uri_prefix
385385
end
386386

387387
class Field < ActiveModelSerializers::Model
388-
attributes :name, :value, :verified_at, :account, :errors
388+
attributes :name, :value, :verified_at, :account
389389

390390
def initialize(account, attributes)
391-
@account = account
392-
@attributes = attributes
393-
@name = attributes['name'].strip[0, string_limit]
394-
@value = attributes['value'].strip[0, string_limit]
395-
@verified_at = attributes['verified_at']&.to_datetime
396-
@errors = {}
391+
@original_field = attributes
392+
string_limit = account.local? ? 255 : 2047
393+
super(
394+
account: account,
395+
name: attributes['name'].strip[0, string_limit],
396+
value: attributes['value'].strip[0, string_limit],
397+
verified_at: attributes['verified_at']&.to_datetime,
398+
)
397399
end
398400

399401
def verified?
@@ -415,22 +417,12 @@ def verifiable?
415417
end
416418

417419
def mark_verified!
418-
@verified_at = Time.now.utc
419-
@attributes['verified_at'] = @verified_at
420+
self.verified_at = Time.now.utc
421+
@original_field['verified_at'] = verified_at
420422
end
421423

422424
def to_h
423-
{ name: @name, value: @value, verified_at: @verified_at }
424-
end
425-
426-
private
427-
428-
def string_limit
429-
if account.local?
430-
255
431-
else
432-
2047
433-
end
425+
{ name: name, value: value, verified_at: verified_at }
434426
end
435427
end
436428

app/models/home_feed.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
class HomeFeed < Feed
44
def initialize(account)
5-
@type = :home
6-
@id = account.id
75
@account = account
6+
super(:home, account.id)
87
end
98

109
def regenerating?
11-
redis.exists?("account:#{@id}:regeneration")
10+
redis.exists?("account:#{@account.id}:regeneration")
1211
end
1312
end

app/models/list_feed.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
class ListFeed < Feed
44
def initialize(list)
5-
@type = :list
6-
@id = list.id
5+
super(:list, list.id)
76
end
87
end

app/models/poll.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ class Option < ActiveModelSerializers::Model
7373
attributes :id, :title, :votes_count, :poll
7474

7575
def initialize(poll, id, title, votes_count)
76-
@poll = poll
77-
@id = id
78-
@title = title
79-
@votes_count = votes_count
76+
super(
77+
poll: poll,
78+
id: id,
79+
title: title,
80+
votes_count: votes_count,
81+
)
8082
end
8183
end
8284

app/models/public_feed.rb

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class PublicFeed < Feed
3+
class PublicFeed
44
# @param [Account] account
55
# @param [Hash] options
66
# @option [Boolean] :with_replies
@@ -33,28 +33,30 @@ def get(limit, max_id = nil, since_id = nil, min_id = nil)
3333

3434
private
3535

36+
attr_reader :account, :options
37+
3638
def with_reblogs?
37-
@options[:with_reblogs]
39+
options[:with_reblogs]
3840
end
3941

4042
def with_replies?
41-
@options[:with_replies]
43+
options[:with_replies]
4244
end
4345

4446
def local_only?
45-
@options[:local]
47+
options[:local]
4648
end
4749

4850
def remote_only?
49-
@options[:remote]
51+
options[:remote]
5052
end
5153

5254
def account?
53-
@account.present?
55+
account.present?
5456
end
5557

5658
def media_only?
57-
@options[:only_media]
59+
options[:only_media]
5860
end
5961

6062
def public_scope
@@ -82,9 +84,9 @@ def media_only_scope
8284
end
8385

8486
def account_filters_scope
85-
Status.not_excluded_by_account(@account).tap do |scope|
86-
scope.merge!(Status.not_domain_blocked_by_account(@account)) unless local_only?
87-
scope.merge!(Status.in_chosen_languages(@account)) if @account.chosen_languages.present?
87+
Status.not_excluded_by_account(account).tap do |scope|
88+
scope.merge!(Status.not_domain_blocked_by_account(account)) unless local_only?
89+
scope.merge!(Status.in_chosen_languages(account)) if account.chosen_languages.present?
8890
end
8991
end
9092
end

app/models/tag_feed.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ class TagFeed < PublicFeed
1313
# @option [Boolean] :remote
1414
# @option [Boolean] :only_media
1515
def initialize(tag, account, options = {})
16-
@tag = tag
17-
@account = account
18-
@options = options
16+
@tag = tag
17+
super(account, options)
1918
end
2019

2120
# @param [Integer] limit
@@ -40,15 +39,15 @@ def get(limit, max_id = nil, since_id = nil, min_id = nil)
4039
private
4140

4241
def tagged_with_any_scope
43-
Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(@options[:any])))
42+
Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(options[:any])))
4443
end
4544

4645
def tagged_with_all_scope
47-
Status.group(:id).tagged_with_all(tags_for(@options[:all]))
46+
Status.group(:id).tagged_with_all(tags_for(options[:all]))
4847
end
4948

5049
def tagged_with_none_scope
51-
Status.group(:id).tagged_with_none(tags_for(@options[:none]))
50+
Status.group(:id).tagged_with_none(tags_for(options[:none]))
5251
end
5352

5453
def tags_for(names)

app/services/keys/claim_service.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ class Result < ActiveModelSerializers::Model
88
:key, :signature
99

1010
def initialize(account, device_id, key_attributes = {})
11-
@account = account
12-
@device_id = device_id
13-
@key_id = key_attributes[:key_id]
14-
@key = key_attributes[:key]
15-
@signature = key_attributes[:signature]
11+
super(
12+
account: account,
13+
device_id: device_id,
14+
key_id: key_attributes[:key_id],
15+
key: key_attributes[:key],
16+
signature: key_attributes[:signature],
17+
)
1618
end
1719
end
1820

app/services/keys/query_service.rb

+11-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ class Result < ActiveModelSerializers::Model
77
attributes :account, :devices
88

99
def initialize(account, devices)
10-
@account = account
11-
@devices = devices || []
10+
super(
11+
account: account,
12+
devices: devices || [],
13+
)
1214
end
1315

1416
def find(device_id)
@@ -20,11 +22,13 @@ class Device < ActiveModelSerializers::Model
2022
attributes :device_id, :name, :identity_key, :fingerprint_key
2123

2224
def initialize(attributes = {})
23-
@device_id = attributes[:device_id]
24-
@name = attributes[:name]
25-
@identity_key = attributes[:identity_key]
26-
@fingerprint_key = attributes[:fingerprint_key]
27-
@claim_url = attributes[:claim_url]
25+
super(
26+
device_id: attributes[:device_id],
27+
name: attributes[:name],
28+
identity_key: attributes[:identity_key],
29+
fingerprint_key: attributes[:fingerprint_key],
30+
)
31+
@claim_url = attributes[:claim_url]
2832
end
2933

3034
def valid_claim_url?

lib/paperclip/color_extractor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def hsl_to_rgb(h, s, l)
142142
g = 0.0
143143
b = 0.0
144144

145-
if s == 0.0
145+
if s.zero?
146146
r = l.to_f
147147
g = l.to_f
148148
b = l.to_f # achromatic

0 commit comments

Comments
 (0)