1
0
Fork 1
forked from fedi/mastodon

Audofix Rubocop Style/WordArray (#23739)

This commit is contained in:
Nick Schonning 2023-02-20 00:14:10 -05:00 committed by GitHub
parent 4552685f6b
commit bf785df9fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 27 additions and 50 deletions

View file

@ -2667,26 +2667,3 @@ Style/UnpackFirst:
Exclude: Exclude:
- 'app/models/concerns/account_interactions.rb' - 'app/models/concerns/account_interactions.rb'
- 'lib/paperclip/gif_transcoder.rb' - 'lib/paperclip/gif_transcoder.rb'
# Offense count: 25
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
Exclude:
- 'db/migrate/20170610000000_add_statuses_index_on_account_id_id.rb'
- 'db/migrate/20180514140000_revert_index_change_on_statuses_for_api_v1_accounts_account_id_statuses.rb'
- 'lib/mastodon/maintenance_cli.rb'
- 'lib/tasks/statistics.rake'
- 'spec/controllers/api/v1/blocks_controller_spec.rb'
- 'spec/controllers/api/v1/bookmarks_controller_spec.rb'
- 'spec/controllers/api/v1/favourites_controller_spec.rb'
- 'spec/controllers/api/v1/mutes_controller_spec.rb'
- 'spec/controllers/settings/applications_controller_spec.rb'
- 'spec/controllers/settings/preferences/other_controller_spec.rb'
- 'spec/models/account_spec.rb'
- 'spec/models/account_statuses_cleanup_policy_spec.rb'
- 'spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb'
- 'spec/services/activitypub/process_account_service_spec.rb'
- 'spec/services/delete_account_service_spec.rb'
- 'spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb'

View file

@ -6,7 +6,7 @@ class AddStatusesIndexOnAccountIdId < ActiveRecord::Migration[5.1]
# of an account to show them in his status page is one of the most # of an account to show them in his status page is one of the most
# significant examples. # significant examples.
# Add this index to improve the performance in such cases. # Add this index to improve the performance in such cases.
add_index 'statuses', ['account_id', 'id'], algorithm: :concurrently, name: 'index_statuses_on_account_id_id' add_index 'statuses', %w(account_id id), algorithm: :concurrently, name: 'index_statuses_on_account_id_id'
remove_index 'statuses', algorithm: :concurrently, column: 'account_id', name: 'index_statuses_on_account_id' remove_index 'statuses', algorithm: :concurrently, column: 'account_id', name: 'index_statuses_on_account_id'
end end

View file

@ -10,6 +10,6 @@ class RevertIndexChangeOnStatusesForApiV1AccountsAccountIdStatuses < ActiveRecor
# These index may not exists (see migration 20180514130000) # These index may not exists (see migration 20180514130000)
remove_index :statuses, column: [:account_id, :id, :visibility], where: 'visibility IN (0, 1, 2)', algorithm: :concurrently if index_exists?(:statuses, [:account_id, :id, :visibility], where: 'visibility IN (0, 1, 2)') remove_index :statuses, column: [:account_id, :id, :visibility], where: 'visibility IN (0, 1, 2)', algorithm: :concurrently if index_exists?(:statuses, [:account_id, :id, :visibility], where: 'visibility IN (0, 1, 2)')
remove_index :statuses, column: [:account_id, :id], where: 'visibility = 3', algorithm: :concurrently if index_exists?(:statuses, ['account_id', 'id'], where: '(visibility = 3)') remove_index :statuses, column: [:account_id, :id], where: 'visibility = 3', algorithm: :concurrently if index_exists?(:statuses, %w(account_id id), where: '(visibility = 3)')
end end
end end

View file

@ -289,7 +289,7 @@ module Mastodon
end end
@prompt.say 'Restoring account domain blocks indexes…' @prompt.say 'Restoring account domain blocks indexes…'
ActiveRecord::Base.connection.add_index :account_domain_blocks, ['account_id', 'domain'], name: 'index_account_domain_blocks_on_account_id_and_domain', unique: true ActiveRecord::Base.connection.add_index :account_domain_blocks, %w(account_id domain), name: 'index_account_domain_blocks_on_account_id_and_domain', unique: true
end end
def deduplicate_account_identity_proofs! def deduplicate_account_identity_proofs!
@ -303,7 +303,7 @@ module Mastodon
end end
@prompt.say 'Restoring account identity proofs indexes…' @prompt.say 'Restoring account identity proofs indexes…'
ActiveRecord::Base.connection.add_index :account_identity_proofs, ['account_id', 'provider', 'provider_username'], name: 'index_account_proofs_on_account_and_provider_and_username', unique: true ActiveRecord::Base.connection.add_index :account_identity_proofs, %w(account_id provider provider_username), name: 'index_account_proofs_on_account_and_provider_and_username', unique: true
end end
def deduplicate_announcement_reactions! def deduplicate_announcement_reactions!
@ -317,7 +317,7 @@ module Mastodon
end end
@prompt.say 'Restoring announcement_reactions indexes…' @prompt.say 'Restoring announcement_reactions indexes…'
ActiveRecord::Base.connection.add_index :announcement_reactions, ['account_id', 'announcement_id', 'name'], name: 'index_announcement_reactions_on_account_id_and_announcement_id', unique: true ActiveRecord::Base.connection.add_index :announcement_reactions, %w(account_id announcement_id name), name: 'index_announcement_reactions_on_account_id_and_announcement_id', unique: true
end end
def deduplicate_conversations! def deduplicate_conversations!
@ -359,7 +359,7 @@ module Mastodon
end end
@prompt.say 'Restoring custom_emojis indexes…' @prompt.say 'Restoring custom_emojis indexes…'
ActiveRecord::Base.connection.add_index :custom_emojis, ['shortcode', 'domain'], name: 'index_custom_emojis_on_shortcode_and_domain', unique: true ActiveRecord::Base.connection.add_index :custom_emojis, %w(shortcode domain), name: 'index_custom_emojis_on_shortcode_and_domain', unique: true
end end
def deduplicate_custom_emoji_categories! def deduplicate_custom_emoji_categories!

View file

@ -7,7 +7,7 @@ namespace :mastodon do
task :stats do task :stats do
require 'rails/code_statistics' require 'rails/code_statistics'
[ [
%w(App\ Libraries app/lib), ['App Libraries', 'app/lib'],
%w(Presenters app/presenters), %w(Presenters app/presenters),
%w(Services app/services), %w(Services app/services),
%w(Validators app/validators), %w(Validators app/validators),

View file

@ -37,13 +37,13 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
it 'sets pagination header for next path' do it 'sets pagination header for next path' do
blocks = 2.times.map { Fabricate(:block, account: user.account) } blocks = 2.times.map { Fabricate(:block, account: user.account) }
get :index, params: { limit: 1, since_id: blocks[0] } get :index, params: { limit: 1, since_id: blocks[0] }
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1]) expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
end end
it 'sets pagination header for previous path' do it 'sets pagination header for previous path' do
block = Fabricate(:block, account: user.account) block = Fabricate(:block, account: user.account)
get :index get :index
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_blocks_url(since_id: block) expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq api_v1_blocks_url(since_id: block)
end end
it 'returns http success' do it 'returns http success' do

View file

@ -63,8 +63,8 @@ RSpec.describe Api::V1::BookmarksController, type: :controller do
get :index, params: { limit: 1 } get :index, params: { limit: 1 }
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq "http://test.host/api/v1/bookmarks?limit=1&max_id=#{bookmark.id}" expect(response.headers['Link'].find_link(%w(rel next)).href).to eq "http://test.host/api/v1/bookmarks?limit=1&max_id=#{bookmark.id}"
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq "http://test.host/api/v1/bookmarks?limit=1&min_id=#{bookmark.id}" expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq "http://test.host/api/v1/bookmarks?limit=1&min_id=#{bookmark.id}"
end end
it 'does not add pagination headers if not necessary' do it 'does not add pagination headers if not necessary' do

View file

@ -63,8 +63,8 @@ RSpec.describe Api::V1::FavouritesController, type: :controller do
get :index, params: { limit: 1 } get :index, params: { limit: 1 }
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq "http://test.host/api/v1/favourites?limit=1&max_id=#{favourite.id}" expect(response.headers['Link'].find_link(%w(rel next)).href).to eq "http://test.host/api/v1/favourites?limit=1&max_id=#{favourite.id}"
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq "http://test.host/api/v1/favourites?limit=1&min_id=#{favourite.id}" expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq "http://test.host/api/v1/favourites?limit=1&min_id=#{favourite.id}"
end end
it 'does not add pagination headers if not necessary' do it 'does not add pagination headers if not necessary' do

View file

@ -37,13 +37,13 @@ RSpec.describe Api::V1::MutesController, type: :controller do
it 'sets pagination header for next path' do it 'sets pagination header for next path' do
mutes = 2.times.map { Fabricate(:mute, account: user.account) } mutes = 2.times.map { Fabricate(:mute, account: user.account) }
get :index, params: { limit: 1, since_id: mutes[0] } get :index, params: { limit: 1, since_id: mutes[0] }
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_mutes_url(limit: 1, max_id: mutes[1]) expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v1_mutes_url(limit: 1, max_id: mutes[1])
end end
it 'sets pagination header for previous path' do it 'sets pagination header for previous path' do
mute = Fabricate(:mute, account: user.account) mute = Fabricate(:mute, account: user.account)
get :index get :index
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_mutes_url(since_id: mute) expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq api_v1_mutes_url(since_id: mute)
end end
it 'returns http success' do it 'returns http success' do

View file

@ -73,7 +73,7 @@ describe Settings::ApplicationsController do
name: 'My New App', name: 'My New App',
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
website: 'http://google.com', website: 'http://google.com',
scopes: ['read', 'write', 'follow'], scopes: %w(read write follow),
}, },
} }
response response

View file

@ -23,7 +23,7 @@ describe Settings::Preferences::OtherController do
expect(response).to redirect_to(settings_preferences_other_path) expect(response).to redirect_to(settings_preferences_other_path)
user.reload user.reload
expect(user.locale).to eq 'en' expect(user.locale).to eq 'en'
expect(user.chosen_languages).to eq ['es', 'fr'] expect(user.chosen_languages).to eq %w(es fr)
end end
it 'updates user settings' do it 'updates user settings' do

View file

@ -895,7 +895,7 @@ RSpec.describe Account, type: :model do
describe 'partitioned' do describe 'partitioned' do
it 'returns a relation of accounts partitioned by domain' do it 'returns a relation of accounts partitioned by domain' do
matches = ['a', 'b', 'a', 'b'] matches = %w(a b a b)
matches.size.times.to_a.shuffle.each do |index| matches.size.times.to_a.shuffle.each do |index|
matches[index] = Fabricate(:account, domain: matches[index]) matches[index] = Fabricate(:account, domain: matches[index])
end end

View file

@ -262,7 +262,7 @@ RSpec.describe AccountStatusesCleanupPolicy, type: :model do
let!(:direct_message) { Fabricate(:status, created_at: 1.year.ago, account: account, visibility: :direct) } let!(:direct_message) { Fabricate(:status, created_at: 1.year.ago, account: account, visibility: :direct) }
let!(:self_faved) { Fabricate(:status, created_at: 1.year.ago, account: account) } let!(:self_faved) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:self_bookmarked) { Fabricate(:status, created_at: 1.year.ago, account: account) } let!(:self_bookmarked) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:status_with_poll) { Fabricate(:status, created_at: 1.year.ago, account: account, poll_attributes: { account: account, voters_count: 0, options: ['a', 'b'], expires_in: 2.days }) } let!(:status_with_poll) { Fabricate(:status, created_at: 1.year.ago, account: account, poll_attributes: { account: account, voters_count: 0, options: %w(a b), expires_in: 2.days }) }
let!(:status_with_media) { Fabricate(:status, created_at: 1.year.ago, account: account) } let!(:status_with_media) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:faved4) { Fabricate(:status, created_at: 1.year.ago, account: account) } let!(:faved4) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:faved5) { Fabricate(:status, created_at: 1.year.ago, account: account) } let!(:faved5) { Fabricate(:status, created_at: 1.year.ago, account: account) }

View file

@ -29,7 +29,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService, type: :service d
end end
it 'sets expected tags as pinned tags' do it 'sets expected tags as pinned tags' do
expect(actor.featured_tags.map(&:display_name)).to match_array ['Foo', 'bar', 'baZ'] expect(actor.featured_tags.map(&:display_name)).to match_array %w(Foo bar baZ)
end end
end end

View file

@ -12,7 +12,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
attachment: [ attachment: [
{ type: 'PropertyValue', name: 'Pronouns', value: 'They/them' }, { type: 'PropertyValue', name: 'Pronouns', value: 'They/them' },
{ type: 'PropertyValue', name: 'Occupation', value: 'Unit test' }, { type: 'PropertyValue', name: 'Occupation', value: 'Unit test' },
{ type: 'PropertyValue', name: 'non-string', value: ['foo', 'bar'] }, { type: 'PropertyValue', name: 'non-string', value: %w(foo bar) },
], ],
}.with_indifferent_access }.with_indifferent_access
end end

View file

@ -50,9 +50,9 @@ RSpec.describe DeleteAccountService, type: :service do
it 'deletes associated target notifications' do it 'deletes associated target notifications' do
expect { subject }.to change { expect { subject }.to change {
[ %w(
'poll', 'favourite', 'status', 'mention', 'follow' poll favourite status mention follow
].map { |type| Notification.where(type: type).count } ).map { |type| Notification.where(type: type).count }
}.from([1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0]) }.from([1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0])
end end
end end

View file

@ -19,7 +19,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
[ [
{ {
'concurrency' => 2, 'concurrency' => 2,
'queues' => ['push', 'default'], 'queues' => %w(push default),
}, },
] ]
end end
@ -82,7 +82,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
describe '#get_budget' do describe '#get_budget' do
context 'on a single thread' do context 'on a single thread' do
let(:process_set_stub) { [{ 'concurrency' => 1, 'queues' => ['push', 'default'] }] } let(:process_set_stub) { [{ 'concurrency' => 1, 'queues' => %w(push default) }] }
it 'returns a low value' do it 'returns a low value' do
expect(subject.compute_budget).to be < 10 expect(subject.compute_budget).to be < 10
@ -92,7 +92,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
context 'on a lot of threads' do context 'on a lot of threads' do
let(:process_set_stub) do let(:process_set_stub) do
[ [
{ 'concurrency' => 2, 'queues' => ['push', 'default'] }, { 'concurrency' => 2, 'queues' => %w(push default) },
{ 'concurrency' => 2, 'queues' => ['push'] }, { 'concurrency' => 2, 'queues' => ['push'] },
{ 'concurrency' => 2, 'queues' => ['push'] }, { 'concurrency' => 2, 'queues' => ['push'] },
{ 'concurrency' => 2, 'queues' => ['push'] }, { 'concurrency' => 2, 'queues' => ['push'] },