Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Lint/UselessAssignment cop #27472

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 0 additions & 21 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,6 @@ Lint/UnusedBlockArgument:
- 'config/initializers/paperclip.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.
Metrics/AbcSize:
Max: 144
Expand Down
2 changes: 0 additions & 2 deletions app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ def update_media_attachments!
end
end

added_media_attachments = @next_media_attachments - previous_media_attachments

@status.ordered_media_attachment_ids = @next_media_attachments.map(&:id)

@media_attachments_changed = true if @status.ordered_media_attachment_ids != previous_media_attachments_ids
Expand Down
3 changes: 0 additions & 3 deletions config/initializers/3_omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
end

Devise.setup do |config|
# Devise omniauth strategies
options = {}

# CAS strategy
if ENV['CAS_ENABLED'] == 'true'
cas_options = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def up
# Record suspend date of blocks and silences for users whose limitations match
# a domain block
DomainBlock.where(severity: [:silence, :suspend]).find_each do |block|
scope = block.accounts
if block.suspend?
block.accounts.where(suspended: true).in_batches.update_all(suspended_at: block.created_at)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def up
# Record suspend date of blocks and silences for users whose limitations match
# a domain block
DomainBlock.where(severity: [:silence, :suspend]).find_each do |block|
scope = block.accounts
if block.suspend?
block.accounts.where(suspended: true).in_batches.update_all(suspended_at: block.created_at)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def success
end

it 'sets link headers' do
account = Fabricate(:account, username: 'username')
Fabricate(: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"'
end
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/jsonld_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@
it 'deems a safe compacting as such' do
json['object'].delete('convo')
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(safe_for_forwarding?(json, compacted)).to be true
end

it 'deems an unsafe compacting as such' do
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(safe_for_forwarding?(json, compacted)).to be false
end
Expand Down
8 changes: 4 additions & 4 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
end

it 'does not return suspended users' do
match = Fabricate(
Fabricate(
:account,
display_name: 'Display Name',
username: 'username',
Expand Down Expand Up @@ -483,7 +483,7 @@
end

it 'does not return non-followed accounts' do
match = Fabricate(
Fabricate(
:account,
display_name: 'A & l & i & c & e',
username: 'username',
Expand All @@ -495,7 +495,7 @@
end

it 'does not return suspended users' do
match = Fabricate(
Fabricate(
:account,
display_name: 'Display Name',
username: 'username',
Expand Down Expand Up @@ -535,7 +535,7 @@
end

it 'does not return suspended users' do
match = Fabricate(
Fabricate(
:account,
display_name: 'Display Name',
username: 'username',
Expand Down
2 changes: 1 addition & 1 deletion spec/models/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

describe '#replies_count' 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
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

describe '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)
expect(described_class.confirmed).to contain_exactly(confirmed_user)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/webauthn_credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
end

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.valid?
Expand All @@ -47,7 +47,7 @@

it 'is invalid if user already registered a webauthn credential with the same nickname' do
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.valid?
Expand Down
8 changes: 4 additions & 4 deletions spec/services/account_search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,30 @@
service = instance_double(ResolveAccountService, call: nil)
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')
end

it 'does not follow the remote account when resolve is false' do
service = instance_double(ResolveAccountService, call: nil)
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)
end
end

it 'returns the fuzzy match first, and does not return suspended exacts' do
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)

expect(results.size).to eq 1
expect(results).to eq [partial]
end

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)

expect(results.size).to eq 0
Expand Down
4 changes: 2 additions & 2 deletions spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

it 'processes duplicate mentions correctly' do
account = Fabricate(:account)
mentioned_account = Fabricate(:account, username: 'alice')
Fabricate(:account, username: 'alice')

expect do
subject.call(account, text: '@alice @alice @alice hey @alice')
Expand Down Expand Up @@ -212,7 +212,7 @@
account = Fabricate(:account)
media = Fabricate(:media_attachment, account: Fabricate(:account))

status = subject.call(
subject.call(
account,
text: 'test status update',
media_ids: [media.id]
Expand Down
2 changes: 1 addition & 1 deletion spec/services/precompute_feed_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
muted_account = Fabricate(:account)
Fabricate(:mute, account: account, target_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)

Expand Down
4 changes: 2 additions & 2 deletions spec/services/resolve_url_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

describe '#call' do
it 'returns nil when there is no resource url' do
url = 'http://example.com/missing-resource'
known_account = Fabricate(:account, uri: url, domain: 'example.com')
url = 'http://example.com/missing-resource'
Fabricate(:account, uri: url, domain: 'example.com')
service = instance_double(FetchResourceService)

allow(FetchResourceService).to receive(:new).and_return service
Expand Down
4 changes: 2 additions & 2 deletions spec/views/statuses/show.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
it 'has valid opengraph tags' do
alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
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(:account, alice)
Expand All @@ -32,7 +32,7 @@
it 'has twitter player tag' do
alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
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(:account, alice)
Expand Down