Autofix Rubocop Rails/Pluck (#23730)
This commit is contained in:
		
					parent
					
						
							
								597767a9f7
							
						
					
				
			
			
				commit
				
					
						21bf326356
					
				
			
		
					 7 changed files with 14 additions and 25 deletions
				
			
		|  | @ -2435,17 +2435,6 @@ Rails/Output: | |||
|   Exclude: | ||||
|     - 'lib/mastodon/ip_blocks_cli.rb' | ||||
| 
 | ||||
| # Offense count: 14 | ||||
| # This cop supports safe autocorrection (--autocorrect). | ||||
| Rails/Pluck: | ||||
|   Exclude: | ||||
|     - 'app/lib/importer/base_importer.rb' | ||||
|     - 'app/lib/link_details_extractor.rb' | ||||
|     - 'app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb' | ||||
|     - 'spec/controllers/api/v1/notifications_controller_spec.rb' | ||||
|     - 'spec/controllers/api/v1/suggestions_controller_spec.rb' | ||||
|     - 'spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb' | ||||
| 
 | ||||
| # Offense count: 9 | ||||
| # This cop supports unsafe autocorrection (--autocorrect-all). | ||||
| # Configuration parameters: Include. | ||||
|  |  | |||
|  | @ -45,7 +45,7 @@ class Importer::BaseImporter | |||
|   # Remove documents from the index that no longer exist in the database | ||||
|   def clean_up! | ||||
|     index.scroll_batches do |documents| | ||||
|       ids           = documents.map { |doc| doc['_id'] } | ||||
|       ids           = documents.pluck('_id') | ||||
|       existence_map = index.adapter.target.where(id: ids).pluck(:id).each_with_object({}) { |id, map| map[id.to_s] = true } | ||||
|       tmp           = ids.reject { |id| existence_map[id] } | ||||
| 
 | ||||
|  |  | |||
|  | @ -188,7 +188,7 @@ class LinkDetailsExtractor | |||
|   end | ||||
| 
 | ||||
|   def language | ||||
|     valid_locale_or_nil(structured_data&.language || opengraph_tag('og:locale') || document.xpath('//html').map { |element| element['lang'] }.first) | ||||
|     valid_locale_or_nil(structured_data&.language || opengraph_tag('og:locale') || document.xpath('//html').pick('lang')) | ||||
|   end | ||||
| 
 | ||||
|   def icon | ||||
|  | @ -220,15 +220,15 @@ class LinkDetailsExtractor | |||
|   end | ||||
| 
 | ||||
|   def link_tag(name) | ||||
|     document.xpath("//link[@rel=\"#{name}\"]").map { |link| link['href'] }.first | ||||
|     document.xpath("//link[@rel=\"#{name}\"]").pick('href') | ||||
|   end | ||||
| 
 | ||||
|   def opengraph_tag(name) | ||||
|     document.xpath("//meta[@property=\"#{name}\" or @name=\"#{name}\"]").map { |meta| meta['content'] }.first | ||||
|     document.xpath("//meta[@property=\"#{name}\" or @name=\"#{name}\"]").pick('content') | ||||
|   end | ||||
| 
 | ||||
|   def meta_tag(name) | ||||
|     document.xpath("//meta[@name=\"#{name}\"]").map { |meta| meta['content'] }.first | ||||
|     document.xpath("//meta[@name=\"#{name}\"]").pick('content') | ||||
|   end | ||||
| 
 | ||||
|   def structured_data | ||||
|  |  | |||
|  | @ -67,7 +67,7 @@ class Scheduler::AccountsStatusesCleanupScheduler | |||
|   end | ||||
| 
 | ||||
|   def compute_budget | ||||
|     threads = Sidekiq::ProcessSet.new.select { |x| x['queues'].include?('push') }.map { |x| x['concurrency'] }.sum | ||||
|     threads = Sidekiq::ProcessSet.new.select { |x| x['queues'].include?('push') }.pluck('concurrency').sum | ||||
|     [PER_THREAD_BUDGET * threads, MAX_BUDGET].min | ||||
|   end | ||||
| 
 | ||||
|  |  | |||
|  | @ -70,19 +70,19 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do | |||
|       end | ||||
| 
 | ||||
|       it 'includes reblog' do | ||||
|         expect(body_as_json.map { |x| x[:type] }).to include 'reblog' | ||||
|         expect(body_as_json.pluck(:type)).to include 'reblog' | ||||
|       end | ||||
| 
 | ||||
|       it 'includes mention' do | ||||
|         expect(body_as_json.map { |x| x[:type] }).to include 'mention' | ||||
|         expect(body_as_json.pluck(:type)).to include 'mention' | ||||
|       end | ||||
| 
 | ||||
|       it 'includes favourite' do | ||||
|         expect(body_as_json.map { |x| x[:type] }).to include 'favourite' | ||||
|         expect(body_as_json.pluck(:type)).to include 'favourite' | ||||
|       end | ||||
| 
 | ||||
|       it 'includes follow' do | ||||
|         expect(body_as_json.map { |x| x[:type] }).to include 'follow' | ||||
|         expect(body_as_json.pluck(:type)).to include 'follow' | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|  | @ -125,7 +125,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do | |||
| 
 | ||||
|       it 'returns everything but excluded type' do | ||||
|         expect(body_as_json.size).to_not eq 0 | ||||
|         expect(body_as_json.map { |x| x[:type] }.uniq).to_not include 'mention' | ||||
|         expect(body_as_json.pluck(:type).uniq).to_not include 'mention' | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|  | @ -139,7 +139,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do | |||
|       end | ||||
| 
 | ||||
|       it 'returns only requested type' do | ||||
|         expect(body_as_json.map { |x| x[:type] }.uniq).to eq ['mention'] | ||||
|         expect(body_as_json.pluck(:type).uniq).to eq ['mention'] | ||||
|       end | ||||
|     end | ||||
|   end | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ RSpec.describe Api::V1::SuggestionsController, type: :controller do | |||
|       json = body_as_json | ||||
| 
 | ||||
|       expect(json.size).to be >= 1 | ||||
|       expect(json.map { |i| i[:id] }).to include(*[bob, jeff].map { |i| i.id.to_s }) | ||||
|       expect(json.pluck(:id)).to include(*[bob, jeff].map { |i| i.id.to_s }) | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  |  | |||
|  | @ -140,7 +140,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do | |||
|           it 'includes existing credentials in list of excluded credentials' do | ||||
|             get :options | ||||
| 
 | ||||
|             excluded_credentials_ids = JSON.parse(response.body)['excludeCredentials'].map { |credential| credential['id'] } | ||||
|             excluded_credentials_ids = JSON.parse(response.body)['excludeCredentials'].pluck('id') | ||||
|             expect(excluded_credentials_ids).to match_array(user.webauthn_credentials.pluck(:external_id)) | ||||
|           end | ||||
|         end | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue