Fix Lint/UselessAssignment cop (#27472)

This commit is contained in:
Matt Jankowski 2023-10-19 10:55:06 -04:00 committed by GitHub
parent 7bc8f03162
commit bcd0171e5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 22 additions and 50 deletions

View file

@ -48,27 +48,6 @@ Lint/UnusedBlockArgument:
- 'config/initializers/paperclip.rb' - 'config/initializers/paperclip.rb'
- 'config/initializers/simple_form.rb' - 'config/initializers/simple_form.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/UselessAssignment:
Exclude:
- 'app/services/activitypub/process_status_update_service.rb'
- 'config/initializers/3_omniauth.rb'
- 'db/migrate/20190511134027_add_silenced_at_suspended_at_to_accounts.rb'
- 'db/post_migrate/20190511152737_remove_suspended_silenced_account_fields.rb'
- 'spec/controllers/api/v1/favourites_controller_spec.rb'
- 'spec/controllers/concerns/account_controller_concern_spec.rb'
- 'spec/helpers/jsonld_helper_spec.rb'
- 'spec/models/account_spec.rb'
- 'spec/models/domain_block_spec.rb'
- 'spec/models/status_spec.rb'
- 'spec/models/user_spec.rb'
- 'spec/models/webauthn_credentials_spec.rb'
- 'spec/services/account_search_service_spec.rb'
- 'spec/services/post_status_service_spec.rb'
- 'spec/services/precompute_feed_service_spec.rb'
- 'spec/services/resolve_url_service_spec.rb'
- 'spec/views/statuses/show.html.haml_spec.rb'
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize: Metrics/AbcSize:
Max: 144 Max: 144

View file

@ -97,8 +97,6 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
end end
end end
added_media_attachments = @next_media_attachments - previous_media_attachments
@status.ordered_media_attachment_ids = @next_media_attachments.map(&:id) @status.ordered_media_attachment_ids = @next_media_attachments.map(&:id)
@media_attachments_changed = true if @status.ordered_media_attachment_ids != previous_media_attachments_ids @media_attachments_changed = true if @status.ordered_media_attachment_ids != previous_media_attachments_ids

View file

@ -9,9 +9,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do
end end
Devise.setup do |config| Devise.setup do |config|
# Devise omniauth strategies
options = {}
# CAS strategy # CAS strategy
if ENV['CAS_ENABLED'] == 'true' if ENV['CAS_ENABLED'] == 'true'
cas_options = {} cas_options = {}

View file

@ -19,7 +19,6 @@ class AddSilencedAtSuspendedAtToAccounts < ActiveRecord::Migration[5.2]
# Record suspend date of blocks and silences for users whose limitations match # Record suspend date of blocks and silences for users whose limitations match
# a domain block # a domain block
DomainBlock.where(severity: [:silence, :suspend]).find_each do |block| DomainBlock.where(severity: [:silence, :suspend]).find_each do |block|
scope = block.accounts
if block.suspend? if block.suspend?
block.accounts.where(suspended: true).in_batches.update_all(suspended_at: block.created_at) block.accounts.where(suspended: true).in_batches.update_all(suspended_at: block.created_at)
else else

View file

@ -18,7 +18,6 @@ class RemoveSuspendedSilencedAccountFields < ActiveRecord::Migration[5.2]
# Record suspend date of blocks and silences for users whose limitations match # Record suspend date of blocks and silences for users whose limitations match
# a domain block # a domain block
DomainBlock.where(severity: [:silence, :suspend]).find_each do |block| DomainBlock.where(severity: [:silence, :suspend]).find_each do |block|
scope = block.accounts
if block.suspend? if block.suspend?
block.accounts.where(suspended: true).in_batches.update_all(suspended_at: block.created_at) block.accounts.where(suspended: true).in_batches.update_all(suspended_at: block.created_at)
else else

View file

@ -62,7 +62,7 @@ describe AccountControllerConcern do
end end
it 'sets link headers' do it 'sets link headers' do
account = Fabricate(:account, username: 'username') Fabricate(:account, username: 'username')
get 'success', params: { account_username: 'username' } get 'success', params: { account_username: 'username' }
expect(response.headers['Link'].to_s).to eq '<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json", <https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"' expect(response.headers['Link'].to_s).to eq '<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json", <https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"'
end end

View file

@ -158,14 +158,14 @@ describe JsonLdHelper do
it 'deems a safe compacting as such' do it 'deems a safe compacting as such' do
json['object'].delete('convo') json['object'].delete('convo')
compacted = compact(json) compacted = compact(json)
deemed_compatible = patch_for_forwarding!(json, compacted) patch_for_forwarding!(json, compacted)
expect(compacted['to']).to eq ['https://www.w3.org/ns/activitystreams#Public'] expect(compacted['to']).to eq ['https://www.w3.org/ns/activitystreams#Public']
expect(safe_for_forwarding?(json, compacted)).to be true expect(safe_for_forwarding?(json, compacted)).to be true
end end
it 'deems an unsafe compacting as such' do it 'deems an unsafe compacting as such' do
compacted = compact(json) compacted = compact(json)
deemed_compatible = patch_for_forwarding!(json, compacted) patch_for_forwarding!(json, compacted)
expect(compacted['to']).to eq ['https://www.w3.org/ns/activitystreams#Public'] expect(compacted['to']).to eq ['https://www.w3.org/ns/activitystreams#Public']
expect(safe_for_forwarding?(json, compacted)).to be false expect(safe_for_forwarding?(json, compacted)).to be false
end end

View file

@ -356,7 +356,7 @@ RSpec.describe Account do
end end
it 'does not return suspended users' do it 'does not return suspended users' do
match = Fabricate( Fabricate(
:account, :account,
display_name: 'Display Name', display_name: 'Display Name',
username: 'username', username: 'username',
@ -483,7 +483,7 @@ RSpec.describe Account do
end end
it 'does not return non-followed accounts' do it 'does not return non-followed accounts' do
match = Fabricate( Fabricate(
:account, :account,
display_name: 'A & l & i & c & e', display_name: 'A & l & i & c & e',
username: 'username', username: 'username',
@ -495,7 +495,7 @@ RSpec.describe Account do
end end
it 'does not return suspended users' do it 'does not return suspended users' do
match = Fabricate( Fabricate(
:account, :account,
display_name: 'Display Name', display_name: 'Display Name',
username: 'username', username: 'username',
@ -535,7 +535,7 @@ RSpec.describe Account do
end end
it 'does not return suspended users' do it 'does not return suspended users' do
match = Fabricate( Fabricate(
:account, :account,
display_name: 'Display Name', display_name: 'Display Name',
username: 'username', username: 'username',

View file

@ -166,7 +166,7 @@ RSpec.describe Status do
describe '#replies_count' do describe '#replies_count' do
it 'is the number of replies' do it 'is the number of replies' do
reply = Fabricate(:status, account: bob, thread: subject) Fabricate(:status, account: bob, thread: subject)
expect(subject.replies_count).to eq 1 expect(subject.replies_count).to eq 1
end end

View file

@ -63,7 +63,7 @@ RSpec.describe User do
describe 'confirmed' do describe 'confirmed' do
it 'returns an array of users who are confirmed' do it 'returns an array of users who are confirmed' do
unconfirmed_user = Fabricate(:user, confirmed_at: nil) Fabricate(:user, confirmed_at: nil)
confirmed_user = Fabricate(:user, confirmed_at: Time.zone.now) confirmed_user = Fabricate(:user, confirmed_at: Time.zone.now)
expect(described_class.confirmed).to contain_exactly(confirmed_user) expect(described_class.confirmed).to contain_exactly(confirmed_user)
end end

View file

@ -37,7 +37,7 @@ RSpec.describe WebauthnCredential do
end end
it 'is invalid if already exist a webauthn credential with the same external id' do it 'is invalid if already exist a webauthn credential with the same external id' do
existing_webauthn_credential = Fabricate(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw') Fabricate(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw')
new_webauthn_credential = Fabricate.build(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw') new_webauthn_credential = Fabricate.build(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw')
new_webauthn_credential.valid? new_webauthn_credential.valid?
@ -47,7 +47,7 @@ RSpec.describe WebauthnCredential do
it 'is invalid if user already registered a webauthn credential with the same nickname' do it 'is invalid if user already registered a webauthn credential with the same nickname' do
user = Fabricate(:user) user = Fabricate(:user)
existing_webauthn_credential = Fabricate(:webauthn_credential, user_id: user.id, nickname: 'USB Key') Fabricate(:webauthn_credential, user_id: user.id, nickname: 'USB Key')
new_webauthn_credential = Fabricate.build(:webauthn_credential, user_id: user.id, nickname: 'USB Key') new_webauthn_credential = Fabricate.build(:webauthn_credential, user_id: user.id, nickname: 'USB Key')
new_webauthn_credential.valid? new_webauthn_credential.valid?

View file

@ -56,7 +56,7 @@ describe AccountSearchService, type: :service do
service = instance_double(ResolveAccountService, call: nil) service = instance_double(ResolveAccountService, call: nil)
allow(ResolveAccountService).to receive(:new).and_return(service) allow(ResolveAccountService).to receive(:new).and_return(service)
results = subject.call('newuser@remote.com', nil, limit: 10, resolve: true) subject.call('newuser@remote.com', nil, limit: 10, resolve: true)
expect(service).to have_received(:call).with('newuser@remote.com') expect(service).to have_received(:call).with('newuser@remote.com')
end end
@ -64,14 +64,14 @@ describe AccountSearchService, type: :service do
service = instance_double(ResolveAccountService, call: nil) service = instance_double(ResolveAccountService, call: nil)
allow(ResolveAccountService).to receive(:new).and_return(service) allow(ResolveAccountService).to receive(:new).and_return(service)
results = subject.call('newuser@remote.com', nil, limit: 10, resolve: false) subject.call('newuser@remote.com', nil, limit: 10, resolve: false)
expect(service).to_not have_received(:call) expect(service).to_not have_received(:call)
end end
end end
it 'returns the fuzzy match first, and does not return suspended exacts' do it 'returns the fuzzy match first, and does not return suspended exacts' do
partial = Fabricate(:account, username: 'exactness') partial = Fabricate(:account, username: 'exactness')
exact = Fabricate(:account, username: 'exact', suspended: true) Fabricate(:account, username: 'exact', suspended: true)
results = subject.call('exact', nil, limit: 10) results = subject.call('exact', nil, limit: 10)
expect(results.size).to eq 1 expect(results.size).to eq 1
@ -79,7 +79,7 @@ describe AccountSearchService, type: :service do
end end
it 'does not return suspended remote accounts' do it 'does not return suspended remote accounts' do
remote = Fabricate(:account, username: 'a', domain: 'remote', display_name: 'e', suspended: true) Fabricate(:account, username: 'a', domain: 'remote', display_name: 'e', suspended: true)
results = subject.call('a@example.com', nil, limit: 2) results = subject.call('a@example.com', nil, limit: 2)
expect(results.size).to eq 0 expect(results.size).to eq 0

View file

@ -155,7 +155,7 @@ RSpec.describe PostStatusService, type: :service do
it 'processes duplicate mentions correctly' do it 'processes duplicate mentions correctly' do
account = Fabricate(:account) account = Fabricate(:account)
mentioned_account = Fabricate(:account, username: 'alice') Fabricate(:account, username: 'alice')
expect do expect do
subject.call(account, text: '@alice @alice @alice hey @alice') subject.call(account, text: '@alice @alice @alice hey @alice')
@ -212,7 +212,7 @@ RSpec.describe PostStatusService, type: :service do
account = Fabricate(:account) account = Fabricate(:account)
media = Fabricate(:media_attachment, account: Fabricate(:account)) media = Fabricate(:media_attachment, account: Fabricate(:account))
status = subject.call( subject.call(
account, account,
text: 'test status update', text: 'test status update',
media_ids: [media.id] media_ids: [media.id]

View file

@ -27,7 +27,7 @@ RSpec.describe PrecomputeFeedService, type: :service do
muted_account = Fabricate(:account) muted_account = Fabricate(:account)
Fabricate(:mute, account: account, target_account: muted_account) Fabricate(:mute, account: account, target_account: muted_account)
reblog = Fabricate(:status, account: muted_account) reblog = Fabricate(:status, account: muted_account)
status = Fabricate(:status, account: account, reblog: reblog) Fabricate(:status, account: account, reblog: reblog)
subject.call(account) subject.call(account)

View file

@ -8,7 +8,7 @@ describe ResolveURLService, type: :service do
describe '#call' do describe '#call' do
it 'returns nil when there is no resource url' do it 'returns nil when there is no resource url' do
url = 'http://example.com/missing-resource' url = 'http://example.com/missing-resource'
known_account = Fabricate(:account, uri: url, domain: 'example.com') Fabricate(:account, uri: url, domain: 'example.com')
service = instance_double(FetchResourceService) service = instance_double(FetchResourceService)
allow(FetchResourceService).to receive(:new).and_return service allow(FetchResourceService).to receive(:new).and_return service

View file

@ -13,7 +13,7 @@ describe 'statuses/show.html.haml', without_verify_partial_doubles: true do
it 'has valid opengraph tags' do it 'has valid opengraph tags' do
alice = Fabricate(:account, username: 'alice', display_name: 'Alice') alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
status = Fabricate(:status, account: alice, text: 'Hello World') status = Fabricate(:status, account: alice, text: 'Hello World')
media = Fabricate(:media_attachment, account: alice, status: status, type: :video) Fabricate(:media_attachment, account: alice, status: status, type: :video)
assign(:status, status) assign(:status, status)
assign(:account, alice) assign(:account, alice)
@ -32,7 +32,7 @@ describe 'statuses/show.html.haml', without_verify_partial_doubles: true do
it 'has twitter player tag' do it 'has twitter player tag' do
alice = Fabricate(:account, username: 'alice', display_name: 'Alice') alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
status = Fabricate(:status, account: alice, text: 'Hello World') status = Fabricate(:status, account: alice, text: 'Hello World')
media = Fabricate(:media_attachment, account: alice, status: status, type: :video) Fabricate(:media_attachment, account: alice, status: status, type: :video)
assign(:status, status) assign(:status, status)
assign(:account, alice) assign(:account, alice)